Download the .c file at the End of the post.
/* Create a structure Player having data members
team_name,player_name,highest_score. Get data of 5 player from user and
sort the data in the ascending order based on Team Names. */
#include<conio.h>
#include<stdio.h>
void main()
{
struct Player
{
char tname[80];
char pname[80];
int hscore;
}p[5],temp;
int i,j;
clrscr();
for(i=0;i<5;i++)
{
printf("\n");
printf("Enter team name:-");
scanf("%s",p[i].tname);
printf("Enter player name:-");
scanf("%s",p[i].pname);
printf("Enter highest score:-");
scanf("%d",&p[i].hscore);
}
//for sorting
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(p[i].tname,p[j].tname)>0)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
printf("\n TEAM & THEIR DETAILS IN ASCENDING ORDER ACCORDING TO THEIR TEAM NAMES:-\n");
for(i=0;i<5;i++)
{
printf("\n");
printf("\nTeam Name is-> %s",p[i].tname);
printf("\nPlayer Name is-> %s",p[i].pname);
printf("\nHighest Score is-> %d",p[i].hscore);
}
getch();
}
Download the .c file - CLICK HERE
0 comments:
Post a Comment