Advertisement
kkubiakx

C - Lab 3 - 17.10.2018 - Ex2.6

Oct 17th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[]) {
  5.    
  6.     int i=0,j=0;
  7.     float x;
  8.     float avg=0;
  9.     do
  10.     {
  11.         printf("Input a number: ");
  12.         scanf("%f",&x);
  13.         if(x>0)
  14.         {
  15.             avg+=x;
  16.             i++;    
  17.         }
  18.         if(abs(x)<100)
  19.         {  
  20.             if(x==0) break;
  21.             j++;
  22.         }
  23.        
  24.     } while (x!=0);
  25.     if(i!=0)
  26.     {
  27.         avg=avg/i;
  28.         printf("The average of positive numbers equals: %.2f",avg);
  29.     } else printf("The number of positive numbers is 0. Cannot calculate average!");
  30.     printf("\nThe quantity of numbers which absolute value is lower than 100 is: %d",j);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement