Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define SIZE 30
  7.  
  8. typedef struct {
  9. int id;
  10. int help;
  11. char name[SIZE];
  12. char *task;
  13. }student;
  14.  
  15. void swap(int *xp, int *yp)
  16. {
  17. int temp = *xp;
  18. *xp = *yp;
  19. *yp = temp;
  20. }
  21.  
  22.  
  23. void bubbleSort(int arr[], int n)
  24. {
  25. int i, j;
  26. for (i = 0; i < n-1; i++)
  27.  
  28. // Last i elements are already in place
  29. for (j = 0; j < n-i-1; j++)
  30. if (arr[j] > arr[j+1])
  31. swap(&arr[j], &arr[j+1]);
  32. }
  33.  
  34.  
  35. int main(void)
  36. {
  37. int i;
  38. int noSessions;
  39. int noStudents;
  40.  
  41. printf("Enter number of consultation sesssions: ");
  42. scanf("%d",&noSessions);
  43. printf("Enter number of students: ");
  44. scanf("%d",&noStudents);
  45.  
  46. student arr[noStudents];
  47.  
  48. for(i = 0; i < noStudents; i++){
  49. int j = i + 1;
  50. printf("Enter enter student %d ID, name and consultation session.", j);
  51. scanf("%d" "%s" "%d", &arr[i].id, &arr[i].name, &arr[i].help);
  52. }
  53.  
  54. printf("Student ID == Full Name == Consultation Session");
  55.  
  56. for(i = 0; i < noStudents; i++){
  57. printf("\n");
  58. printf("%d <> %s <> %d", arr[i].id, arr[i].name, arr[i].help);
  59. printf("\n");
  60. }
  61.  
  62. bubbleSort(arr, noStudents);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement