Faculty Details

QUESTION

There are faculties in the department, you have to arrange the list of faculties depending upon ID numbers.

ANSWER

#include <stdio.h>
struct emp
{
    char name[10] ;
    int empno ;
 } e[10],temp ;
int main()
{
    int i,j, n ;
    scanf("%d", &n) ;
    for(i = 0 ; i < n ; i++)
    {
     scanf("%s", e[i].name) ;
     scanf("%d", &e[i].empno) ;
    }
  
  for (i = 1; i < n; i++)
  {
      for (j = 0; j < n - i; j++) 
      {
         if (e[j].empno>e[j + 1].empno) 
         {
            temp = e[j];
            e[j] = e[j + 1];
            e[j + 1] = temp;
         }
      }
  }
  printf("After Sorting\n");
  printf("Name ID\n");
     for(i = 0 ; i < n ; i++)
    {
     printf("%s ", e[i].name) ;
     printf("%d\n", e[i].empno) ;
      }
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock