Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #define NUM_SCORE 5
  3. #define MAX_SCORE 102
  4. #define MIN_SCORE 0
  5.  
  6. void getScores (int a[]);
  7. double average (int a[]);
  8. void bubbleSort (int a[]);
  9. void swap (int *p, int*q);
  10.  
  11. main()
  12. {
  13. int firstRun = 1, i;
  14. char repeat = 's';
  15. int a[NUM_SCORE];
  16.  
  17.  
  18. do
  19. {
  20. if (!firstRun)
  21. {
  22. printf("\nEnter 5 midterm scores (0-102):");
  23. for (i=0 ; i < NUM_SCORE ; ++i)
  24. scanf ("%d", &a[i]);
  25. }
  26. if (firstRun)
  27. {
  28. a[0] = 72;
  29. a[1] = 78;
  30. a[2] = 82;
  31. a[3] = 88;
  32. a[4] = 99;
  33. firstRun--;
  34. }
  35. printf(" Array: ");
  36. for ( i=0 ; i<NUM_SCORE ; i++)
  37. printf("%d ", a[i]);
  38. printf("\n Average: %.2lf\n", average(a));
  39. bubbleSort (a);
  40. printf(" Sorted: ");
  41. for ( i=0 ; i<NUM_SCORE ; i++)
  42. printf("%d ", a[i]);
  43. printf("\n Highest: %d", a[NUM_SCORE-1]);
  44.  
  45. printf("\nWant to calculate midterm scores?");
  46. repeat = getchar();
  47. getchar();
  48. }while(repeat != 'n' && repeat != 'N');
  49. }
  50. double average (int a[])
  51. {
  52. double average, sum = 0;
  53. int i;
  54. for ( i=0 ; i<NUM_SCORE ; ++i)
  55. sum = sum + a[i];
  56. average = (sum/NUM_SCORE);
  57.  
  58. return average;
  59. }
  60.  
  61. void bubbleSort (int a[])
  62. {
  63. int i, j;
  64. for(i = 0 ; i < NUM_SCORE-1 ; ++i)
  65. for(j = NUM_SCORE-1 ; i<j ; --j)
  66. if( a[j-1] > a[j])
  67. swap(&a[j-1], &a[j]);
  68. }
  69.  
  70. void swap (int *p, int*q)
  71. /* swap stores the addresses of two numbers passed as paramters to p and q
  72. then swaps the two values stored by the two addresses by storing the
  73. dereferenced value in a placer then assigning the value at p to the
  74. value at q. Then the value at q is changed to the value at p by assigning
  75. it to placer which was previously stored as the value at p. This effectively
  76. switches the values stored at the addresses.*/
  77. {
  78. double placer;
  79. placer = *p;
  80. *p = *q;
  81. *q = placer;
  82. return;
  83. }
  84.  
  85. void getScores (int a[])
  86. {
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement