Write a program in C for mark list analysis using structure
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
struct stud
{
int rno;
char name[15];
int marks[5];
int total;
float avg;
char class[15];
}
st[10],temp;
int i,n,j;
clrscr();
printf(“\n enter\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“\n enter the roll no..”);
scanf(“%d”,&st[i].rno);
printf(“name...\n”);
scanf(“%s”,&st[i].name);
printf(“enter three marks..”);
for(j=1;j<=3;j++)
scanf(“%d”,&st[i].marks[j]);
}
for(i=1;i<=n;i++)
{
st[i].total=0;
for(j=1;j<=3;j++)
{
st[i].total=st[i].total+st[i].marks[j];
}
st[i].avg=st[i].total/30;
if(st[i].avg>=75)
strcpy(st[i].grade,”distinction”);
elseif(st[i].avg>=60)
strcpy(st[i].grade,”first”);
elseif(st[i].avg>=50)
strcpy(st[i].grade,”second”);
else
strcpy(st[i].grade,”fail”);
}
for(i=1;i<=n;i++)
{
for(j=j+1;j<=n;j++)
{
if(st[i].total<st[j].total)
{
temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
printf(“\n the student details in rankwise\n”);
for(i=1;i<=n;i++)
{
printf(“\n\n roll no:%d”,st[i].rno);
printf(“\n name :%s”,st[i].name);
printf(“\n marks in three subjects”);
for(j=1;j<=3;j++)
{
printf(“\n %d,st[i].marks[j]);
}
printf (“\n total: %d”, st[i].total);
printf(“\n average:%f”,st[i].avg);
printf(“\n grade:%s”,st[i].grade);
}
getch();
}
Post a Comment