Addition of array elements, C/C++ Programming

Addition of array elements:

#define rows 3

#define cols 3

void main()

{

                int i=0,j=0,sum=0;

                int arr[rows][cols];

                for (i=0; i<=rows-1; i++)

                                for(j=0;j<=cols-1;j++)

                                {

                                                printf("Enter elements (%d,%d)\n",(i+1),(j+1));

 

                                                scanf("%d",&arr[i][j]);

                                }

                for (i=0; i<=rows-1; i++)

                {

                                printf("\t");       

                                for(j=0;j<3;j++)

                                                {

                                                printf("%3d  ",arr[i][j]);

                                                }

                                                printf("\n");

                }

                printf("\n Sum of matrix\n");

                for(i=0;i<=rows-1;i++)

                                for(j=0;j<=cols-1;j++)

                                {

 

                                                sum=sum+arr[i][j];

                                }

printf("\tsum=%d\n",sum);                       

}

 

Posted Date: 9/29/2012 7:22:30 AM | Location : United States







Related Discussions:- Addition of array elements, Assignment Help, Ask Question on Addition of array elements, Get Answer, Expert's Help, Addition of array elements Discussions

Write discussion on Addition of array elements
Your posts are moderated
Related Questions
Semaphore is used to synchronize processes. whereas mutex is used to give synchronization among threads running in the similar process.

#questiStarting with a blank solution, write a program to prompt the user for an employee number, hourly rate and hours worked. Compute and display the employee number, gross weekl

A: In C++ the access privileges are public, private and protected. The default access level assigned to members of a class is private. Private members of any class are accessible o

Description A long time ago in a galaxy far, far away, the country Mafghanistan had n cities and m old roads, where each road connected a pair of cities. Due to the treacherous mo

c program to construct a structure: struct sensus                 {                                 char name[30];                                 long int population;

array of class objects and single inheritance

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''''''''{'''''''' and end wi

Define a user-defined data type (struct) called Car to represent a car in the context of a car dealership database. Car must have at least the following characteristics: Make Model

C Coding to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can be found

i have an array of structs, and am trying to make a pointer that can point to a certain struct within the array