Assignment Number: 7
PROBLEM STATEMENT:
Write a C program to accept student details and display their result using an array of
structures.
#include <stdio.h>
struct Student
{
int roll;
int m1,m2,m3;
char name[30];
int total;
float per;
};
int main()
{
int i,n;
printf("------------Student information ---------");
printf("\n enter the no of records : ");
scanf("%d",&n);
struct Student strarr[n];
for(i=0;i<n;i++)
{
printf("enter the roll no of student :");
scanf("%d",&strarr[i].roll);
printf("enter the marks of 3 subjects :");
scanf("%d%d%d",&strarr[i].m1,&strarr[i].m2,&strarr[i].m3);
printf("enter the nameof student:");
scanf("%s",strarr[i].name);
strarr[i].total=strarr[i].m1+strarr[i].m2+strarr[i].m3;
strarr[i].per=strarr[i].total/3;
}
printf("\n roll no |\t name|\t marks |\t total |\t per| \tresult |");
for(i=0;i<n;i++)
{
printf("\n %d",strarr[i].roll);
printf("\t\t\t");
puts(strarr[i].name);
printf("\t\t");
printf("\t\t\t%d",strarr[i].m1);
printf("\t %d",strarr[i].m2);
printf("\t%d",strarr[i].m3);
printf("\t\t%d",strarr[i].total);
printf("\t %f",strarr[i].per);
if(strarr[i].per<20)
{
printf("fail");
}
else
printf("pass");
}
return 0;
}