Posts

Search

College

Create a structure called College. struct College { char name[100]; char city[100]; int establishmentYear; float passPercentage; } Write a program to get the details of 'n' colleges and to display their details, sorted by name in ascending order.
INPUT & OUTPUT FORMAT:
Refer sample input and output for formatting specification.
All float values are displayed corrected to 2 decimal places.
SAMPLE INPUT & OUTPUT:
Enter the number of colleges
3
Enter the details of college 1
Enter name
ACE
Enter city
Coimbatore
Enter year of establishment
2000
Enter pass percentage
98.5
Enter the details of college 2
Enter name
BCE
Enter city
Erode
Enter year of establishment
1990
Enter pass percentage
89.45
Enter the details of college 3
Enter name
DCE
Enter city
Chennai
Enter year of establishment
2008
Enter pass percentage
97.35
Details of colleges
College 1
Name : ACE
City : Coimbatore
Year of establishment : 2000
Pass percentage : 98.50
College 2
Name : BCE
City : Erode
Year of establishment : 1990
Pass percentage : 89.45
College 3
Name : DCE
City : Chennai
Year of establishment : 2008
Pass percentage : 97.35

CODE :-
#include<stdio.h>
#include<string.h>
struct College{char name[100];
              char city[100];
               int establishmentYear;
               char passPercentage[1000];
              }S1[20],temp;
int main(){
  
  int n,i,j;
      printf("Enter the number of colleges\n");
  scanf("%d",&n);
  for(i=0;i<n;i++){
  printf("Enter the details of college %d",i+1);
  printf("\nEnter name\nEnter city\nEnter year of establishment\nEnter pass percentage\n");
  scanf("%s %s %d %s",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;
         }
      }
  printf("Details of colleges\n");

   for (i = 0; i < n; i++) {
    printf("College:%d",i+1);
      printf("\nName:%s\nCity:%s\nYear of establishment:%d\nPass percentage:%s\n",S1[i].name,S1[i].city,S1[i].establishmentYear,S1[i].passPercentage);
   }
  return 0;
}