# Store information about 5 students using structure

### Write a program to store information about 5 students (Id, name and Five Subject marks) using Structure. Find the sum, total of a given five subjects and sorting students according their marks and print output in table format.

``````Source Code:

#include<stdio.h>
#include<conio.h>
struct student
{
int no;
char name[10];
int marks[5];
float avg;
};
void main()
{
struct student s1[5],temp;
int i,j,total_marks[5];
clrscr();
for(i=0;i<5;i++)
{
printf("Enter the student no:");
scanf("%d",&s1[i].no);
flushall();
printf("Enter the student name:");
gets(s1[i].name);
flushall();
printf("Enter the five subject marks ");
total_marks[i]=0;
for(j=0;j<5;j++)
{
scanf("%d",&s1[i].marks[j]);
total_marks[i]=total_marks[i]+s1[i].marks[j];
}
s1[i].avg=(float)total_marks[i]/5;
}
printf("No \t Name \t M-1 \t M-2 \t M-3 \t M-4 \t M-5 \t Total \t Avg \n");
for(i=0;i<5;i++)
{
printf("%d \t",s1[i].no);
printf("%s \t",s1[i].name);
for(j=0;j<5;j++)
{
printf("%d \t",s1[i].marks[j]);
}
printf("%d \t",total_marks[i]);
printf("%f \t",s1[i].avg);
printf("\n");
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(s1[i].avg>s1[j].avg)
{
temp=s1[i];
s1[i]=s1[j];
s1[j]=temp;

}
}
}
Printf(“Descending order Student List \n”);
printf("No \t Name \t M-1 \t M-2 \t M-3 \t M-4 \t M-5 \t Total \t Avg \n");
for(i=0;i<5;i++)
{
printf("%d \t",s1[i].no);
printf("%s \t",s1[i].name);
for(j=0;j<5;j++)
{
printf("%d \t",s1[i].marks[j]);
}
printf("%d \t",total_marks[i]);
printf("%f \t",s1[i].avg);
printf("\n");
}
getch();
}

Output:

Enter the student no: 100
Enter the student name: Bhavesh
Enter the five subject marks:
50
60
70
80
50

Enter the student no: 101
Enter the student name: Abbhilasha
Enter the five subject marks:
55
65
75
85
55

Enter the student no: 102
Enter the student name: Priyanka
Enter the five subject marks:
56
66
76
86
56

Enter the student no: 103
Enter the student name: Manisha
Enter the five subject marks:
57
67
77
87
57

Enter the student no: 104
Enter the student name: Jainit
Enter the five subject marks:
58
68
78
88
58

No	Name		M-1	M-2	M-3	M-4	M-5	Total	Avg
1	Bhavesh	50	60	70	80	50	310	62
2	Abbhilasha	55	65	75	85	55	335	67
3	Priyanka	56	66	76	86	56	340	68
4	Manisha	57	67	77	87	57	345	69
5 	Jainit		58	68	78	88	58	350	70

Descending order Student List

No	Name		M-1	M-2	M-3	M-4	M-5	Total	Avg
5 	Jainit		58	68	78	88	58	350	70
4	Manisha	57	67	77	87	57	345	69
3	Priyanka	56	66	76	86	56	340	68
2	Abbhilasha	55	65	75	85	55	335	67
1	Bhavesh	50	60	70	80	50	310	62``````