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 and total of a given five subjects and print output in table format.


Source Code:

#include<stdio.h>
#include<conio.h>
struct student
{
	int no;
	char name[20];
	int marks[5];
};
void main()
{
	struct student s1[5];
	int i,j,k,total[5];
	float avg[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[i]=0;
		for(j=0;j<5;j++)
		{
			scanf("%d",&s1[i].marks[j]);
			total[i]=total[i]+s1[i].marks[j];
		}
		avg[i]=(float)total[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[i]);
		printf("%f \t",avg[i]);
		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: 
50
60
70
80
50

Enter the student no: 102
Enter the student name: Priyanka
Enter the five subject marks: 
50
60
70
80
50

Enter the student no: 103
Enter the student name: Manisha
Enter the five subject marks: 
50
60
70
80
50

Enter the student no: 104
Enter the student name: Jainit
Enter the five subject marks: 
50
60
70
80
50

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	50	60	70	80	50	310	62	
3	Priyanka	50	60	70	80	50	310	62
4	Manisha	50	60	70	80	50	310	62
5 	Jainit		50	60	70	80	50	310	62

Leave a Reply

Your email address will not be published. Required fields are marked *