Thursday 21 May 2015

c program to read n number students record and find the worst and best student based on their marks

#include<stdio.h>
struct stud
{
int id;
char name[10];
char branch[10];
struct marks
{
int s1,s2,s3;
}m;
}s[10];
main()
{
int i,f=0,c,del,key,best,max;
clrscr();
do{
printf("\n..............menu....................\n");
printf("1.add\t2.Delete\t3.Display\t4.worst\t5.best\t6.exit\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("Enter ID :");
scanf("%d",&s[f].id);
printf("\nEnter Name :");
scanf("%s",s[f].name);
printf("\nEnter Branch :");
scanf("%s",s[f].branch);
printf("\n Enter marks scored in 3 subjects :");
scanf("%d%d%d",&s[f].m.s1,&s[f].m.s2,&s[f].m.s3);
f++;
break;
case 3:
printf("\nId\tName\tBranch\tsub1\tsub2\tsub3\tTotal\tAVG");
for(i=0;i<f;i++)
{
printf("\n%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d",s[i].id,s[i].name,s[i].branch,s[i].m.s1,s[i].m.s2,s[i].m.s3,s[i].m.s1+s[i].m.s2+s[i].m.s3,s[i].m.s1+s[i].m.s2+s[i].m.s3/3);
}
break;
case 2:
printf("\nEnter the id :");
scanf("%d",&key);
for(i=0;i<f;i++)
{
if(s[i].id==key)
{
del=i;
printf("\nid %d is deleted ",s[i].id);
}
}
for(i=del;i<f;i++)
{
s[i]=s[i+1];
}
f--;
break;
case 5:
max=s[0].m.s1+s[0].m.s2+s[0].m.s3;
for(i=0;i<f;i++)
{
if((s[i].m.s1+s[i].m.s2+s[i].m.s3)>max)
{
max=s[i].m.s1+s[i].m.s2+s[i].m.s3;
best=i+1;
}
}
printf("\nBest student is : %d",best);
break;
}
}while(c!=6);

getch();
}

No comments:

Post a Comment