Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Program to print multiplication table using two-dimensional array

Posted By: Ben Evans     Category: C Programming     Views: 11410

Program to print multiplication table using two-dimensional array.

Code for Program to print multiplication table using two-dimensional array in C Programming

main()                                                      
   {  
       int  i, j, car;                                  
       int  frequency[5][5] = { {0},{0},{0},{0},{0} };  
       char city;                                       
       printf("For each person, enter the city code \n");      
       printf("followed by the car code.\n");                  
       printf("Enter the letter X to indicate end.\n");        
   /*. . . . . . TABULATION BEGINS  . . . . . */
for( i = 1 ; i < 100 ; i++ ) { scanf("%c", &city ); if( city == 'X' ) break; scanf("%d", &car ); switch(city) { case'B' : frequency[1][car]++; break; case'C' : frequency[2][car]++; break; case'D' : frequency[3][car]++; break; case'M' : frequency[4][car]++; break; } } /*. . . . .TABULATION COMPLETED AND PRINTING BEGINS. . . .*/
printf("\n\n"); printf(" POPULARITY TABLE\n\n"); printf("-------------------------------------------\n"); printf("City Ambassador Fiat Dolphin Maruti \n"); printf("-------------------------------------------\n"); for( i = 1 ; i <= 4 ; i++ ) { switch(i) { case 1 : printf("Bombay ") ; break ; case 2 : printf("Calcutta ") ; break ; case 3 : printf("Delhi ") ; break ; case 4 : printf("Madras ") ; break ; } for( j = 1 ; j <= 4 ; j++ ) printf("%7d", frequency[i][j] ) ; printf("\n") ; } printf("-------------------------------------------\n"); /*. . . . . . . . . PRINTING ENDS. . . . . . . . . . .*/
} Output For each person, enter the city code followed by the car code. Enter the letter X to indicate end. M 1 C 2 B 1 D 3 M 2 B 4 C 1 D 3 M 4 B 2 D 1 C 3 D 4 D 4 M 1 M 1 B 3 B 3 C 1 C 1 C 2 M 4 M 4 C 2 D 1 C 2 B 3 M 1 B 1 C 2 D 3 M 4 C 1 D 2 M 3 B 4 X POPULARITY TABLE ------------------------------------------- City Ambassador Fiat Dolphin Maruti ------------------------------------------- Bombay 2 1 3 2 Calcutta 4 5 1 0 Delhi 2 1 3 2 Madras 4 1 1 4 -------------------------------------------
  
Share: 



Ben Evans
Ben Evans author of Program to print multiplication table using two-dimensional array 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!