Structures - 2 College Details

Description:

Create a structure called College. struct College { char name[100]; char city[100]; int establishmentYear; float passPercentage; } The structure variable name "S1" Write a program to get the details of n colleges and to display their details, sorted by college name in ascending order. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Hint: The college name should be in Sorted or in Ascending Order College details are sorted based on their "Names" in ascending order In Test case 1: S comes before T (A B C D E F G H I J K L M N O P Q R S T) In Test case 2: A,K,S(A B C D E F G H I J K L M N O P Q R S T) Note: The structure variables, data members and structure name are CASE Sensitive. Follow the same case mentioned in the mandatory Test Case 1 Input (stdin) 2 SRMUniversity Chennai 1985 97.6 TRPEngineeringCollege Trichy 1998 97.2 Expected Output Details of colleges Name:SRMUniversity City:Chennai Year of establishment:1985 Pass percentage:97.6 Name:TRPEngineeringCollege City:Trichy Year of establishment:1998 Pass percentage:97.2 Test Case 2 Input (stdin) 3 Karunyauniversity Coimbatore 1986 67.2 SastraUniversity Trichy 1987 77.3 Amritauniversity Coimbatore 1988 90.1 Expected Output Details of colleges Name:Amritauniversity City:Coimbatore Year of establishment:1988 Pass percentage:90.1 Name:Karunyauniversity City:Coimbatore Year of establishment:1986 Pass percentage:67.2 Name:SastraUniversity City:Trichy Year of establishment:1987

Program :

#include<stdio.h>
#include<string.h>
struct College{char name[100];
              char city[100];
               int establishmentYear;
               float passPercentage;
              }S1[20],temp;
int main(){
  
  int n,i,j;
      printf("Details of colleges\n");
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%s %s %d %f",S1[i].name,S1[i].city,&S1[i].establishmentYear,&S1[i].passPercentage);
  }
   for (i = 1; i < n; i++)
      for (j = 0; j < n - i; j++) {
         if (strcmp(S1[j].name, S1[j + 1].name) > 0) {
            temp = S1[j];
            S1[j] = S1[j + 1];
            S1[j + 1] = temp;
         }
      }
 
   for (i = 0; i < n; i++) {
      printf("Name:%s\nCity:%s\nYear of establishment:%d\nPass percentage:%.1f\n",S1[i].name,S1[i].city,S1[i].establishmentYear,S1[i].passPercentage);
   }
  return 0;
}