Advertisement
Kyojin96

Arithmetic mean

Nov 23rd, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int n = 0;          //Our input var
  7.     int count = 0;      //Used to count how much numbers we have
  8.     int sum = 0;        //The total sum of positive numbers
  9.     int result = 0;     //The arithmetic mean
  10.  
  11.     //Get first input
  12.     printf("Vuvedete n: ");
  13.     scanf("%d", &n);
  14.  
  15.     //We need continuous input for numbers in range [-100; 100]
  16.     while(n >= -100 && n <= 100)
  17.     {
  18.         //Check if number is positive
  19.         if(n > 0)
  20.         {
  21.             count++; //Increase count
  22.             sum += n; //Add to the total sum
  23.             result = sum / count; //Get arithmetic mean
  24.             printf("  Sredno aritmetichno: %d\n", result);
  25.             printf("   Vuvedete sledvashto n: ");
  26.             scanf("%d", &n);
  27.         }
  28.  
  29.     }
  30.  
  31.     printf("Sredno aritmetichno: %d\n", result);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement