Back To C Structures
//program to create a structure student and calculate percentage based on marks (example of array within a structure) #include
#include
struct student { int rollno; char name[20]; int marks[5]; float percentage; }; void main() { struct student s; float temp=0; int i; clrscr(); printf("\nenter rollno of student "); scanf("%d",&s.rollno); printf("\nenter name of student "); scanf("%s",s.name); for(i=0;i<5;i++) { printf("\nenter marks in subject %d : ",i+1); scanf("%d",&s.marks[i]); temp=temp+s.marks[i]; } printf("\ndisplaying the data "); printf("\nrollno of student is %d",s.rollno); printf("\nname of student is %s",s.name); for(i=0;i<5;i++) { printf("\nmarks of student in subject %d are %d ",i+1,s.marks[i]); } s.percentage=temp/5; printf("\npercentage is %f",s.percentage); getch(); }