Program in C to enter student information and find the sum and percentage Using array of structure variable
#include<stdio.h> #include<stdlib.h> struct Date { int day; int month; int year; }; struct Student { int roll; char name[30]; char clas[10]; struct Date dob; int marks[5]; }; void Input(struct Student *s1) { int i; printf("\nEnter following studetnt details.\n"); printf("Roll No. :-"); scanf("%d",&s1->roll); printf("Name :-"); fflush(stdin); gets(s1->name); printf("Class :-"); scanf("%s",s1->clas); printf("Date of Birth :-"); scanf("%d%d%d",&s1->dob.day,&s1->dob.month,&s1->dob.year); printf("Five Subject marks :-"); for(i=0;i<5;i++) scanf("%d",&s1->marks[i]); } void display(struct Student *s1) { int i; printf("\n%4d %s\t %s\t%d-%d-%d\t",s1->roll,s1->name,s1->clas,s1->dob.day,s1->dob.month,s1->dob.year);; for(i=0;i<5;i++) printf("%6d",s1->marks[i]); printf("%6d\t %.2f",TotalMarks(s1),TotalMarks(s1)/5.0); } int TotalMarks(struct Student s1) { int sum=0,i; for(i=0;i<5;i++) sum+=s1.marks[i]; return sum; } int main() { int ch,i=0,j; struct Student s[20]; while(1) { printf("Press 1 to insert student details."); printf("\nPress 2 to show student details."); printf("\nPress 3 to exit."); printf("\nEnter your choice number:-"); scanf("%d",&ch); switch(ch) { case 1:system("cls"); Input(&s[i]); i++; break; case 2:system("cls"); printf("\n***********************************************************************************************************\n"); printf("Roll No. Name\t Class\tDate of birth\t sub1 sub2 sub3 sub4 sub5 Sum\tPercentage."); printf("\n***********************************************************************************************************\n"); for(j=0;j<i;j++) display(&s[j]); case 3:exit(0); default:printf("Wrong choice."); } } return 0; }
Output:-
0 Comments