Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************
- * array2.c
- *
- * Computer Science 50
- * David J. Malan
- *
- * Computes a student's average across 2 quizzes.
- *
- * Demonstrates C's math library.
- ***************************************************************************/
- #include <cs50.h>
- #include <math.h>
- #include <stdio.h>
- // number of quizzes per term
- #define QUIZZES 2
- int
- main(void)
- {
- float grades[QUIZZES], sum;
- int average, i;
- // ask user for grades
- printf("\nWhat were your quiz scores?\n\n");
- for (i = 0; i < QUIZZES; i++)
- {
- printf("Quiz #%d of %d: ", i+1, QUIZZES);
- grades[i] = GetFloat();
- }
- // compute average
- sum = 0;
- for (i = 0; i < QUIZZES; i++)
- sum += grades[i];
- average = (int) round(sum / QUIZZES);
- // report average
- printf("\nYour average is: %d\n\n", average);
- }
Add Comment
Please, Sign In to add comment