POP Lab Program 10-HMK
POP Lab Program 10-HMK
Write a program to implement structures to read, write and compute average- marks of
the students, list the students scoring above and below the average marks for a class of
N students.
Program
#include <stdio.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");
// storing information
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");
// displaying information
for(i=0; i<n; i++)
{
printf("\nUSN: %s\n",s[i].usn);
printf("Name: "); puts(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);
countav=0; countbv=0;
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);
}
Test Input Parameters Expected Obtained Remarks
No output output
1 N=3, Enter the student details Average Average
marks:520 marks:520
Total No of Total No of
students above students above
USN Name Marks average=1 average=1
Total No of Total No of PASS
S[0] 4GW24CS001 Chetana 500 students below students below
average=2 average=2
S[1] 4GW24CS002 Darshini 510
Viva Questions:
1) Define structure? Differentiate between an array and a structure?
2) Does the definition of a structure create memory space?
3) How do you access a structure variable?
4) What is a enumerated data type in C?
5) Define union? What are the difference between structure and union?
6) What is the use of fflush( ).