Implement structures to read, write and compute average-marks and the students scoring above and below the average marks for a class of N students.

 Implement structures to read, write and compute average-marks and the students scoring above and below the average marks for a class of N students.

#include<stdio.h>
struct student
{

int usn, marks;
char name[20];

}s[20];
void main()
{

int i, n;
float total=0,avg;
printf("Enter the number of student\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{

printf("Enter the %d student details\n",i+1);
printf("Enter the USN:");
scanf("%d",&s[i].usn);
printf("Enter the student name without white spaces:");
scanf("%s",s[i].name);
printf("Enter the marks:");
scanf("%d",&s[i].marks);
total=total+s[i].marks;

}
avg=total/n;

printf("Students scored above the average marks\nUSN\tNAME\tMARKS\n");
for(i=0;i<n;i++)
{

if(s[i].marks>=avg)
{
printf("%d\t%s\t%d\n", s[i].usn,s[i].name,s[i].marks);
}

}
printf("Students scored below the average marks\nUSN\tNAME\tMARKS\n");
for(i=0;i<n;i++)
{
if(s[i].marks<avg)
{

printf("%d\t%s\t%d\n", s[i].usn,s[i].name,s[i].marks);

}

}
}

Comments