Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define NUM_SCORE 5
- #define MAX_SCORE 102
- #define MIN_SCORE 0
- void getScores (int a[]);
- double average (int a[]);
- void bubbleSort (int a[]);
- void swap (int *p, int*q);
- main()
- {
- int firstRun = 1, i;
- char repeat = 's';
- int a[NUM_SCORE];
- do
- {
- if (!firstRun)
- {
- printf("\nEnter 5 midterm scores (0-102):");
- for (i=0 ; i < NUM_SCORE ; ++i)
- scanf ("%d", &a[i]);
- }
- if (firstRun)
- {
- a[0] = 72;
- a[1] = 78;
- a[2] = 82;
- a[3] = 88;
- a[4] = 99;
- firstRun--;
- }
- printf(" Array: ");
- for ( i=0 ; i<NUM_SCORE ; i++)
- printf("%d ", a[i]);
- printf("\n Average: %.2lf\n", average(a));
- bubbleSort (a);
- printf(" Sorted: ");
- for ( i=0 ; i<NUM_SCORE ; i++)
- printf("%d ", a[i]);
- printf("\n Highest: %d", a[NUM_SCORE-1]);
- printf("\nWant to calculate midterm scores?");
- repeat = getchar();
- getchar();
- }while(repeat != 'n' && repeat != 'N');
- }
- double average (int a[])
- {
- double average, sum = 0;
- int i;
- for ( i=0 ; i<NUM_SCORE ; ++i)
- sum = sum + a[i];
- average = (sum/NUM_SCORE);
- return average;
- }
- void bubbleSort (int a[])
- {
- int i, j;
- for(i = 0 ; i < NUM_SCORE-1 ; ++i)
- for(j = NUM_SCORE-1 ; i<j ; --j)
- if( a[j-1] > a[j])
- swap(&a[j-1], &a[j]);
- }
- void swap (int *p, int*q)
- /* swap stores the addresses of two numbers passed as paramters to p and q
- then swaps the two values stored by the two addresses by storing the
- dereferenced value in a placer then assigning the value at p to the
- value at q. Then the value at q is changed to the value at p by assigning
- it to placer which was previously stored as the value at p. This effectively
- switches the values stored at the addresses.*/
- {
- double placer;
- placer = *p;
- *p = *q;
- *q = placer;
- return;
- }
- void getScores (int a[])
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement