Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Use of subscripted members in structures , ARRAYS WITHIN A STRUCTURE

Posted By: Megan Brown     Category: C Programming     Views: 2659

Use of subscripted members in structures , ARRAYS WITHIN A STRUCTURE.

Code for Use of subscripted members in structures , ARRAYS WITHIN A STRUCTURE in C Programming

   main()                                                           
   {                                                                
       struct  marks                                                
       {                                                            
           int  sub[3];                                             
           int  total;                                              
       };                                                           
       struct marks student[3] =                             
       {45,67,81,0,75,53,69,0,57,36,71,0};                   
       struct marks total;                                   
       int  i,j;                                                    
                                                                    
       for(i = 0; i <= 2; i++)                                      
       {                                                            
          for(j = 0; j <= 2; j++)                                   
          {                                                         
             student[i].total += student[i].sub[j];                 
             total.sub[j] += student[i].sub[j];                     
          }                                                         
          total.total += student[i].total;                          
       }                                                            
       printf("STUDENT         TOTAL\n\n");                         
       for(i = 0; i <= 2; i++)                                      
          printf("Student[%d]      %d\n", i+1, student[i].total);  
                                                                    
       printf("\nSUBJECT         TOTAL\n\n");                       
       for(j = 0; j <= 2; j++)                                      
          printf("Subject-%d        %d\n", j+1, total.sub[j]);      
                                                                    
       printf("\nGrand Total  =   %d\n", total.total);              
                                                                    
   }                                                                
                                                                    Output                                                           
                                                                    
   STUDENT         TOTAL                                            
   Student[1]       193                                             
   Student[2]       197                                             
   Student[3]       164                                             
                                                                    
   SUBJECT         TOTAL                                            
   Subject-1        177                                             
   Subject-2        156                                             
   Subject-3        221                                             
                                                                    
   Grand Total  =   554                                             
  
Share: 



Megan Brown
Megan Brown author of Use of subscripted members in structures , ARRAYS WITHIN A STRUCTURE 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!