ProAnswers.org

Write a C program to perform Mark list Analysis using Structures?

#include

#include 

#include 

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(“

enter
”);

scanf(“%d”,&n); 

for(i=1;i<=n;i++) 

{ 

printf(“

enter the roll no…”);

scanf(“%d”,&st[i].rno); 

printf(“name...

”);

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

{ 

temp=st[i]; 

st[i]=st[j]; 

st[j]=temp; 

} 

} 

} 

printf(“

the student details in rankwise
”);

for(i=1;i<=n;i++) 

{ 

printf(“

roll no:%d”,st[i].rno);

printf(“

name :%s”,st[i].name);

printf(“

marks in three subjects”);

for(j=1;j<=3;j++) 

{ 

printf(“

%d,st[i].marks[j]);

} 

printf (“

total: %d”, st[i].total);

printf(“

average:%f”,st[i].avg);

printf(“

grade:%s”,st[i].grade);

} 

getch(); 

} 

Output: 

enter 

1

enter the roll no...105 

name...sheik raja 

enter the three marks...89 

87 

78 

 

the student details in rankwise 

roll no:105 

name:sheik raja 

marks in three subjects 

89 

87 

78 

total:254 

average:84.666664 

grade:distinction