Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*input:
- A sequence of numbers (integers), ending with the digit 0
- 1
- 2
- 3
- 0
- output:
- The average of the given row of numbers, rounded off to 1 digit after the
- comma:
- 2.0
- test:
- Test your developed program on the basis of relevant test scenarios.*/
- //----------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- double bereken_gemiddelde (int getal)
- {
- static int numberInput = 0;
- static int sum = 0;
- sum = sum + numberInput;
- numberInput++;
- return sum / numberInput;
- // calculate and return average so far.
- }
- int main(void)
- {
- double gemiddelde = 0;
- while (1)
- {
- int getal;
- scanf("%d", &getal);
- if (getal == 0)
- break; //stops if getal == 0
- else
- gemiddelde = bereken_gemiddelde(0);
- }
- printf("%.1f\n", gemiddelde);
- //system("PAUSE");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement