We provide Engineering,HSEB notes, tutorials which can be helpful for students during college life.
Tuesday, April 7, 2015
35. Write a program to store name and mark of 20 students. Sort the data according with mark in descending order and display them. [2066]
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char name[20][30],temp_name[30];
int marks[20],temp_marks,i,j;
clrscr();
printf("\n Input name and total marks of 20 students:- ");
for(i=0;i<5;i++)
{
fflush(stdin);
gets(name[i]):
scanf("%d",&mark[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
(marks[i]<marks[j])
{
strcpy(temp_name,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp_name);
temp_marks = marks[i];
marks[i] = marks[j];
marks[j] = temp_marks;
}
}
}
printf("\n The name and marks in descending order");
printf(“\n Name \t Marks");
for(i=0,i<5;i++)
printf("\n%s\t%3d",name[i],marks[i]);
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment