Program to show 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

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!