Advertisement
anonymzz

Untitled

May 5th, 2023
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. //Exercise 3
  2. #include <stdio.h>
  3. int main( void )
  4. {//function main begings
  5.     int s, p; //declaring variables
  6.     double sales[4][5]; //declaring 2d array
  7.     double total[5] = {0,0,0,0,0};//declaring 1d array
  8.    
  9.     for( s = 0 ; s < 4 ; ++s ){//for loop for get inputs begings
  10.        
  11.         printf( "Sales Person %d \n", s+1 );
  12.        
  13.         for( p = 0 ; p < 5 ; ++p ){
  14.            
  15.             printf( "Product Number %d\n", p+1 );
  16.             printf( "Input total dollar value of that product sold that day : ");
  17.             scanf( "%lf", &sales[s][p]);
  18.                
  19.            
  20.         }
  21.         printf( "\n" );
  22.     }//for loop for get inputs ends
  23.    
  24.     for( p =0 ; p<5 ; ++p ){//for loop for cal total begings
  25.        
  26.         for( s=0 ; s<4 ; ++s ){
  27.            
  28.             total[p] = total[p] + sales[s][p];
  29.            
  30.         }
  31.        
  32.         printf( "Product %d Total sales : %.2f", p+1, total[p]);
  33.         printf("\n" );
  34.     }//for loop for cal total ends
  35.    
  36.    
  37. return 0;  
  38. }//end of the main function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement