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
Constructor public class ListNode {    // package access members; List can access these directly private E data; // data for this node privateListNode nextNode; /

Write a program 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 b

Literals (Constants) Constants are data storage locations whose address is not accessible for the user. Their value is not altered during the course of the program. Literal

Define How Passing Arrays to a Function? A complete array can be passed to a function as an argument. The manner in which the array is passed be different from that of an ordin

We can combine more than one variable on the same line i.e.   float number1,number2,number3; etc Sometimes we want to mix the variable types used on the same line, this could

Draw a picture using line: void main(void) {     int   driver = DETECT,mode;     int   x[10],y[10];     int   x_center = 360, y_center = 180, rad = 100;     int

Consider a group of n robots, numbered R2D1 through R2Dn, and m tasks, numbered 1 through m. Tasks can be different and robots are specialized, hence a given robot can only perform

one of the segments is showing compilation error...

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th

C program to check display days and month main() {           int months, days;           clrscr();           printf("ENTER DAYS: ");           scanf("%d", &days);