cricket
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct cricket
  5. {
  6.  char player_name[20];
  7.  char team_name[20];
  8.  float batting_avg;
  9. }p[50],t;
  10.  
  11. int main(void)
  12. {
  13.  int i=0,j=0,n=50;
  14.  
  15.  for(i=0;i<n;i++)
  16.  {
  17.   printf("n Enter Player Name : ");
  18.   scanf("%s",p[i].player_name);
  19.   printf("n Enter Team Name : ");
  20.   scanf("%s",p[i].team_name);
  21.   printf("n Enter Batting Average : ");
  22.   scanf("%f",&p[i].batting_avg);
  23.  }
  24.  for(i=0;i<n-1;i++)
  25.  {
  26.   for(j=i;j<n;j++)
  27.   {
  28.    if(strcmp(p[i].team_name,p[j].team_name)>0)
  29.    {
  30.     t=p[i];
  31.     p[i]=p[j];
  32.     p[j]=t;
  33.    }
  34.   }
  35.  }
  36.  
  37.  j=0;
  38.  for(i=0;i<n;i++)
  39.  {
  40.   if(strcmp(p[i].team_name,p[j].team_name)!=0 || i==0)
  41.   {
  42.    printf("n Team Name: %s",p[i].team_name);
  43.    j=i;
  44.   }
  45.   printf("n Player Name     = %s",p[i].player_name);
  46.   printf("n Batting Average = %f",p[i].batting_avg);
  47.  }
  48.  return 0;
  49. }
Parsed in 0.010 seconds