PROGRAM 10-
Implement structures to read, write, compute average- marks and the
students scoring above and below the average marks for a class of N students.
ALGORITHM-
Step 1 : Start
Step 2 : Define a Structure Student with members
usn,name,marks, Define a structure variable s
Step 3 : Read n
Step 4: for i0 to n do
Read s[i].usn, s[i].name,s[i].marks sumsum+s[i].marks
end for
Step 5 : avg←sum/n
Step 6 : Print avg
Step 7 : Print “Details of student who scored above average marks” for i0 to n do
if(s[i].marks>=avg)then
Print s[i].usn,s[i].name,s[i].marks
end if
end for
Step 8 : Print “Details of student who scored below average marks” for i0 to n do
if(s[i].marks<avg)then
Print s[i].usn,s[i].name,s[i].marks
end for
Step 9 : Stop
FLOWCHART-
PROGRAM-
#include<stdio.h>
struct student
{
int marks,usn;
char name[100];
};
void main()
{
struct student s[100];
int i,n;
float sum=0.0,avg=0.0;
printf("Enter the number of students\n");
scanf("%d",&n);
printf("Enter the student details\n");
printf("\n usn\t name\t marks\n");
for(i=0;i<n;i++)
{
scanf("%d%s%d",&s[i].usn,s[i].name,&s[i].marks);
sum=sum+s[i].marks;
}
avg=sum/n;
printf ("Average marks is %f",avg);
printf("Students who scored above average marks:\n");
printf("\nusn \t name \t marks \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("\nStudents scored below average marks:\n");
printf("\n usn\t name\t marks \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);
}
}
}