Tuesday, January 17, 2012

Mark list Analysis using Structures


#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();
}

Output:
enter
2
enter the roll no...105
name...sheik raja
enter the three marks...89
87
78
enter roll no...110
name...sriram
enter the three marks...98
96
95

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

roll no:110
name:sriram
marks in three subjects
98
96
95
total:289
average:96.3333336
grade:distinction 

No comments:

Post a Comment