Skip to main content

C Program using array of structure

/*C Program to accept ‘n’ students information like Rollno, Name, Marks of 4 subjects . Calculate the total and average of marks using structure*/ 
 
 #include<stdio.h> 
 struct StudentInfo 
 { int Rno; 
 char Sname[20]; 
 int marks[4]; 
 float avg; 
 }s[10]; 
 void main() 
 { int i, j, n, total; 
 printf("\n How many students info you want to enter? "); scanf("%d",&n); 
 printf("\n Enter student information RNo, Name, Marks of 4 subjects.");
 for(i=0;i<n;i++) 
 { 
 total=0; 
 scanf("%d%s",&s[i].Rno, s[i].Sname); 
 for(j=0;j<4;j++) 
 { scanf("%d", &s[i].marks[j]); 
 total=total + s[i].marks[j]; 
 }  
 s[i].avg=(float)total/4; 
 } 
 printf("\nThe student details are:"); 
 for(i=0;i<n;i++) 
 {  
 printf("\nRollno %d is %s and has average marks .2f",s[i].Rno,s[i].Sname,s[i].avg);  
 } 
 }

Comments