Advertisement
MAT4m

Untitled

Jan 20th, 2019
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. struct Student
  5. {
  6. int ID;
  7. char name[50];
  8. int points;
  9.  
  10. }ar[200];
  11.  
  12.  
  13. int main(){ int i,n,swap,j;
  14.  
  15. printf("Pass the number of students to the program: ");
  16. scanf("%d",&n);
  17.  
  18. for(i=1;i<=n;++i)
  19. {
  20. printf("Input ID of student %d: ", i);
  21. scanf("%d",&ar[i].ID );
  22.  
  23. printf("Input name of student %d: ", i);
  24. scanf("%s", &ar[i].name);
  25.  
  26. printf("Input points of student %d: ", i);
  27. scanf("%d", &ar[i].points); }
  28.  
  29.  
  30. printf("BEFORE SORT");
  31. for(i=1;i<n+1;i++)
  32. {
  33. printf("\nID %d is %d ", i, ar[i].ID);
  34.  
  35. printf("\tName %d is %s ", i,ar[i].name);
  36.  
  37. printf("\tPoints %d are %d ", i, ar[i].points);
  38. }
  39.  
  40. for(i=0;i<n-1;i++)
  41. {
  42. for(j=0;j<n-i;j++)
  43. {struct Student swap;
  44. if(ar[j].points>ar[j+1].points){
  45. swap=ar[j];
  46. ar[j]=ar[j+1];
  47. ar[j+1]=swap;
  48. }}
  49.  
  50. }
  51. printf("\nSORTED IN ASCENDING ORDER");
  52. for(i=1;i<n+1;i++)
  53.  
  54. {
  55. printf("\nID %d is %d ", i, ar[i].ID);
  56.  
  57. printf("\tName %d is %s ", i,ar[i].name);
  58.  
  59. printf("\tPoints %d are %d ", i, ar[i].points);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement