Design a structure students to contain name, BOD and total marks obtained. Use the date structure (day.month, year) to read data for 5 students in class and display list of students in rank-wise.
struct date
{
int d,m,y;
};
struct student
{
int rollno;
char name[10];
char studclass[10];
int result;
struct date bod;
};
void main()
{
int i,j,temp;
struct student s[5];// structure array
int rk;
clrscr();
printf("\n Structure Array program");
for(i=0;i<5;i++)
{
printf("\n enter student's information as rollno, name, class and result ");
scanf("%d%s%s%d",&s[i].rollno,&s[i].name,&s[i].studclass,&s[i].result);
printf("\n enter bod of student");
scanf("%d%d%d",&s[i].bod.d,&s[i].bod.m,&s[i].bod.y);
}
printf("\n Given students information:");
for(i=0;i<5;i++)
{
printf("\n student %d: %d %s %s ",i+1,s[i].rollno,s[i].name,s[i].studclass);
printf(" %d %d %d %d",s[i].result,s[i].bod.d,s[i].bod.m,s[i].bod.y);
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(s[i].result<s[i].result)
{
temp=s[i].result;
s[i].result=s[j].result;
s[j].result=temp;
}
}
}
printf("\n Students information rankwise:");
rk=1;
for(i=0;i<5;i++)
{
printf("\n Rank %d student %d %s %d ",rk,s[i].rollno,s[i].name,s[i].result);
rk++;
}
getch();
}
output:
0 Comments
Post a Comment