Advertisement
HeekoOfficial

wtf

Feb 20th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*input:
  2. A sequence of numbers (integers), ending with the digit 0
  3. 1
  4. 2
  5. 3
  6. 0
  7. output:
  8. The average of the given row of numbers, rounded off to 1 digit after the
  9.         comma:
  10. 2.0
  11. test:
  12. Test your developed program on the basis of relevant test scenarios.*/
  13. //----------------------------------------------------------------------------------------------------------------
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <stdbool.h>
  17.  
  18.     double bereken_gemiddelde (int getal)
  19.     {
  20.         static int numberInput = 0;
  21.         static int sum = 0;
  22.         sum = sum + numberInput;
  23.         numberInput++;
  24.         return  sum / numberInput;
  25.         // calculate and return average so far.
  26.     }
  27.     int main(void)
  28.     {
  29.         double gemiddelde = 0;
  30.         while (1)
  31.         {
  32.             int getal;
  33.             scanf("%d", &getal);
  34.             if (getal == 0)
  35.                 break; //stops if getal == 0
  36.             else
  37.                 gemiddelde = bereken_gemiddelde(0);
  38.         }
  39.         printf("%.1f\n", gemiddelde);
  40.         //system("PAUSE");
  41.         return 1;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement