S2-1
Write a program in ‘C’ language, which accepts Enrolment number,
Name Aggregate marks secured in a Program by a student.
Assign ranks to students according to the marks secured.
Rank-1 should be awarded to the students who secured the
highest marks and so on. The program should print the
enrolment number, name of the student and the rank
secured in ascending order.
#include<stdio.h>
#include<conio.h>
struct stud
{
int roll;
int mark;
char name[15];
};
void main()
{
struct stud S[10], t;
int i, j, n;
clrscr();
printf("Enter number of studentsn");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("Enter roll no., name, markn");
scanf("%d%s%d",&S[i].roll,&S[i].name,&S[i].mark);
}
for(i=0;i<n-1;i++)
for(j=i+1;j<n-1;j++)
if(S[i].mark < S[j].mark)
{
t=S[i];
S[i]=S[j];
S[j]=t;
}
printf("nRank Listnn");
printf("Roll No Name Mark Rankn");
for(i=0;i<n;++i)
printf("%dt%st%dt%dn",S[i].roll,S[i].name,S[i].mark,i+1);
getch();
}
Page 1

Bcsl 033 data and file structures lab s2-1

  • 1.
    S2-1 Write a programin ‘C’ language, which accepts Enrolment number, Name Aggregate marks secured in a Program by a student. Assign ranks to students according to the marks secured. Rank-1 should be awarded to the students who secured the highest marks and so on. The program should print the enrolment number, name of the student and the rank secured in ascending order. #include<stdio.h> #include<conio.h> struct stud { int roll; int mark; char name[15]; }; void main() { struct stud S[10], t; int i, j, n; clrscr(); printf("Enter number of studentsn"); scanf("%d",&n); for(i=0;i<n;++i) { printf("Enter roll no., name, markn"); scanf("%d%s%d",&S[i].roll,&S[i].name,&S[i].mark); } for(i=0;i<n-1;i++) for(j=i+1;j<n-1;j++) if(S[i].mark < S[j].mark) { t=S[i]; S[i]=S[j]; S[j]=t; } printf("nRank Listnn"); printf("Roll No Name Mark Rankn"); for(i=0;i<n;++i) printf("%dt%st%dt%dn",S[i].roll,S[i].name,S[i].mark,i+1); getch(); } Page 1