Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Illustration of subscripted structure variables , ARRAYS OF STRUCTURES

Posted By: Owen Bouchard     Category: C Programming     Views: 3666

Illustration of subscripted structure variables , ARRAYS OF STRUCTURES.

Code for Illustration of subscripted structure variables , ARRAYS OF STRUCTURES in C Programming

struct marks                                                     
   {
       int  sub1;                                                   
       int  sub2;                                                   
       int  sub3;                                                   
       int  total;                                                  
   };                                                               
   main()                                                           
   {
       int  i;                                                      
       struct marks student[3] =  {{45,67,81,0},             
                                   {75,53,69,0},             
                                   {57,36,71,0}};            
       struct marks total;                                   
       for(i = 0; i <= 2; i++)                                      
       {                                                            
           student[i].total = student[i].sub1 +                     
                              student[i].sub2 +                     
                              student[i].sub3;                      
           total.sub1 = total.sub1 + student[i].sub1;               
           total.sub2 = total.sub2 + student[i].sub2;               
           total.sub3 = total.sub3 + student[i].sub3;               
           total.total = 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("\n SUBJECT          TOTAL\n\n");                     
       printf("%s       %d\n%s       %d\n%s       %d\n",            
              "Subject 1   ", total.sub1,                           
              "Subject 2   ", total.sub2,                           
              "Subject 3   ", total.sub3);                          
                                                                    
       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: 



Owen Bouchard
Owen Bouchard author of Illustration of subscripted structure variables , ARRAYS OF STRUCTURES is from Montreal, Canada.
 
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!