PGM 9
PGM 9
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.
Algorithm Step 1: Start
Step 2: Create a structure with student including fields usn,name and marks. Step 3: Initialize the
variables countav=0,countbv=0
Step 5: Read the value of usn, name and marks for the specified no of students using structure variable
s[i] for i=0 to n-1
Step 6: Display the details of students Step 7: Repeat for i=0 ton-1
Flow Chart:
#include<stdio.h>
#include<stdlib.h>
struct student
{
char usn[50];
char name[50];
int marks;
} s[10];
void main()
{
int i,n,countav=0,countbv=0;
float sum,average;
printf("Enter number of Students\n");
scanf("%d",&n);
printf("Enter information of students:\n");
for(i=0; i<n;i++)
{
printf("Enter USN: ");
scanf("%s",s[i].usn);
printf("Enter name: ");
scanf("%s",s[i].name);
printf("Enter marks: ");
scanf("%d",&s[i].marks);
printf("\n");
}
printf("Displaying Information:\n\n");
for(i=0; i<n; i++)
{
printf("\nUSN: %s\n",s[i].usn);
printf("Name: %s\n ", s[i].name);
printf("Marks: %d",s[i].marks);
printf("\n");
}
for(i=0;i<n;i++)
{
sum=sum+s[i].marks;
}
average=sum/n;
printf("\nAverage marks: %f",average);
for(i=0;i<n;i++)
{
if(s[i].marks>=average)
countav++;
else
countbv++;
}
printf("\nTotal No of students above average= %d",countav);
printf("\nTotal No of students below average= %d",countbv);
getch();
}