Student Name List

QUESTION

If you are class teacher, you have some number of students in your class. You have to prepare the namelist for attendance in the alphabetical order.

ANSWER

#include <stdio.h>
#include<string.h>
int main()
{
  int limit,i,j,temp1;
  char temp[15];
  struct data
  {
    char name[10];
    int marks;
  }d[15];
 scanf("%d",&limit);
  for(i=0;i<limit;i++)
  {
    scanf("%s%d",d[i].name,&d[i].marks);
  }
  for(i=0;i<limit;i++)
  {
    for(j=i+1;j<limit;j++)
    {
    if(strcmp(d[j].name,d[i].name)<0)
    {
      strcpy(temp,d[i].name);
      strcpy(d[i].name,d[j].name);
      strcpy(d[j].name,temp);
       temp1=d[i].marks;
      d[i].marks=d[j].marks;
      d[j].marks=temp1;
    }
    }
  }
  printf("\nAfter sorting");
  printf("\nName ID");
  for(i=0;i<limit;i++)
  {
    printf("\n%s %d",d[i].name,d[i].marks);
  }
	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.