0
4.3kviews
Write a program to accept marks of five student using array and print it out in ascending order
1 Answer
written 3.0 years ago by | • modified 3.0 years ago |
#include<stdio.h>
#include<conio.h>
struct student
{
int Roll_No,Marks;
char Fname[25];
}stud[100],t;
void main()
{
int i,j,n;
printf("Enter how many students?\n");
scanf("%d",&n);
printf("enter students information in the sequence of Roll Numbers, First Names and Marks\n");
// Take Students' information from the user
for(i=0;i<n;i++)
{
scanf("%d %s %d",&stud[i].Roll_No,stud[i].Fname,&stud[i].Marks);
}
// Arrange marks obtained by Students in Ascending Order
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(stud[j].Marks<stud[i].Marks)
{
t=stud[i];
stud[i]=stud[j];
stud[j]=t;
}
}
}
// Display information of Students' in Ascending Order of Marks
printf("\nStudents' information in Ascending Order according to Marks obtained\n");
printf("\nROLL_NO\t\tFIRST NAME\t\tMARKS\n");
printf("-------------------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t\t\t%s\t\t\t%d\n",stud[i].Roll_No,stud[i].Fname,stud[i].Marks);
}
}