Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Illustration of two-dimensional arrays.

Posted By: Faith Hughes     Category: C Programming     Views: 15003

Illustration of two-dimensional arrays.

Code for Illustration of two-dimensional arrays. in C Programming

#define     MAXGIRLS     4                                  
   #define     MAXITEMS     3                                  
   main()                                                      
   {                                                           
       intvalue[MAXGIRLS][MAXITEMS];                        
       int   girl_total[MAXGIRLS] , item_total[MAXITEMS];      
       int   i, j, grand_total;                                
                                                               
   /*.......READING OF VALUES AND COMPUTING girl_total ...*/
printf("Input data\n"); printf("Enter values, one at a time, row-wise\n\n"); for( i = 0 ; i < MAXGIRLS ; i++ ) { girl_total[i] = 0; for( j = 0 ; j < MAXITEMS ; j++ ) { scanf("%d", &value[i][j]); girl_total[i] = girl_total[i] + value[i][j]; } } /*.......COMPUTING item_total..........................*/
for( j = 0 ; j < MAXITEMS ; j++ ) { item_total[j] = 0; for( i =0 ; i < MAXGIRLS ; i++ ) item_total[j] = item_total[j] + value[i][j]; } /*.......COMPUTING grand_total.........................*/
grand_total = 0; for( i =0 ; i < MAXGIRLS ; i++ ) grand_total = grand_total + girl_total[i]; /* .......PRINTING OF RESULTS...........................*/
printf("\n GIRLS TOTALS\n\n"); for( i = 0 ; i < MAXGIRLS ; i++ ) printf("Salesgirl[%d] = %d\n", i+1, girl_total[i] ); printf("\n ITEM TOTALS\n\n"); for( j = 0 ; j < MAXITEMS ; j++ ) printf("Item[%d] = %d\n", j+1 , item_total[j] ); printf("\nGrand Total = %d\n", grand_total); } Output Input data Enter values, one at a time, row_wise 310 257 365 210 190 325 405 235 240 260 300 380 GIRLS TOTALS Salesgirl[1] = 950 Salesgirl[2] = 725 Salesgirl[3] = 880 Salesgirl[4] = 940 ITEM TOTALS Item[1] = 1185 Item[2] = 1000 Item[3] = 1310 Grand Total = 3495
  
Share: 


Didn't find what you were looking for? Find more on Illustration of two-dimensional arrays. Or get search suggestion and latest updates.

Faith Hughes
Faith Hughes author of Illustration of two-dimensional arrays. is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!