Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4.  
  5. struct person
  6. {
  7. char name[10];
  8. int rno;
  9. };
  10. typedef struct person NAME;
  11. NAME stud[10], temp[10];
  12.  
  13. void main()
  14. {
  15. int no,i;
  16.  
  17. void sort(int N);
  18.  
  19. fflush(stdin);
  20.  
  21. printf("Enter the number of students in the list\n");
  22. scanf("%d",&no);
  23.  
  24. for(i = 0; i < no; i++)
  25. {
  26. printf("\nEnter the name of person %d : ", i+1);
  27. fflush(stdin);
  28. gets(stud[i].name);
  29. }
  30. for(i=0;i<no;i++)
  31. {
  32. printf("%-10s\n",temp[i].name,temp[i].rno);
  33. }
  34.  
  35. sort(no); /* Function call */
  36.  
  37. printf("\n*****************************\n");
  38. printf (" Names after sorting \n");
  39. printf("\n*****************************\n");
  40.  
  41. for(i=0;i<no;i++)
  42. {
  43. printf("%-10s\n",stud[i].name,stud[i].rno);
  44. }
  45.  
  46. printf("\n*****************************\n");
  47. }
  48.  
  49. void sort(int N)
  50. {
  51. int i,j;
  52. NAME temp;
  53.  
  54. for(i = 0; i < N-1;i++)
  55. {
  56. for(j = i+1; j < N; j++)
  57. {
  58. if(strcmp(stud[i].name,stud[j].name) > 0 )
  59. {
  60. temp = stud[i];
  61. stud[i] = stud[j];
  62. stud[j] = temp;
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement