#include<iostream.h>
#include<conio.h>
#include<string.h>
struct player
{
char name[30],country[30];
int No_Of_Matches;
float avg;
} p[50];
void main()
{
int i,j,temp;
char str[30];
clrscr();
for(i=0;i<50;i++)
{
cout<<"Enter the name of player: ";
cin>>p[i].name;
cout<<"Enter the name of country of player: ";
cin>>p[i].country;
cout<<"Enter the number of matches he had played: ";
cin>>p[i].No_Of_Matches;
cout<<"Enter the Batting avg : ";
cin>>p[i].avg;
}
for(i=0;i<50;i++)
{
for(j=1;j<50;j++)
{
if(p[i].avg<p[j].avg)
{
temp=p[i].No_Of_Matches;
p[i].No_Of_Matches=p[j].No_Of_Matches;
p[j].No_Of_Matches=temp;
temp=p[i].avg;
p[i].avg=p[j].avg;
p[j].avg=temp;
strcpy(str,p[i].name);
strcpy(p[i].name,p[j].name);
strcpy(p[j].name,str);
strcpy(str,p[i].country);
strcpy(p[i].country,p[j].country);
strcpy(p[j].country,str);
}
}
}
for(i=0;i<50;i++)
{
cout<<"\nThe name of player: "<<p[i].name;
cout<<"\nThe name of country of player: "<<p[i].country;
cout<<"\nThe number of matches he had played: "<<p[i].No_Of_Matches;
cout<<"\nThe Batting avg : "<<p[i].avg;
}
}
#include<conio.h>
#include<string.h>
struct player
{
char name[30],country[30];
int No_Of_Matches;
float avg;
} p[50];
void main()
{
int i,j,temp;
char str[30];
clrscr();
for(i=0;i<50;i++)
{
cout<<"Enter the name of player: ";
cin>>p[i].name;
cout<<"Enter the name of country of player: ";
cin>>p[i].country;
cout<<"Enter the number of matches he had played: ";
cin>>p[i].No_Of_Matches;
cout<<"Enter the Batting avg : ";
cin>>p[i].avg;
}
for(i=0;i<50;i++)
{
for(j=1;j<50;j++)
{
if(p[i].avg<p[j].avg)
{
temp=p[i].No_Of_Matches;
p[i].No_Of_Matches=p[j].No_Of_Matches;
p[j].No_Of_Matches=temp;
temp=p[i].avg;
p[i].avg=p[j].avg;
p[j].avg=temp;
strcpy(str,p[i].name);
strcpy(p[i].name,p[j].name);
strcpy(p[j].name,str);
strcpy(str,p[i].country);
strcpy(p[i].country,p[j].country);
strcpy(p[j].country,str);
}
}
}
for(i=0;i<50;i++)
{
cout<<"\nThe name of player: "<<p[i].name;
cout<<"\nThe name of country of player: "<<p[i].country;
cout<<"\nThe number of matches he had played: "<<p[i].No_Of_Matches;
cout<<"\nThe Batting avg : "<<p[i].avg;
}
}
0 comments:
Post a Comment