Maszi

7.1

Oct 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int sp = 0;
  7.     int sn = 0;
  8.     int x;
  9.     int counterP=0;
  10.     int counterN=0;
  11.  
  12.     do{
  13.         printf("Podaj liczbe ");
  14.         scanf("%i", &x);
  15.         if(x!=0){
  16.             if(x%2==0){
  17.                 sp = sp + x;
  18.                 counterP++;
  19.             } else {
  20.             sn = sn + x;
  21.             counterN++;
  22.             }
  23.         }
  24.     }while(x!=0);
  25.  
  26.     if(counterN>0){
  27.         float sredniaN = (float)sn/counterN;
  28.         printf("Srednia liczb nieparzystych to: %f \n", sredniaN);
  29.     } else {
  30.         printf("Brak liczb nieparzystych \n");
  31.     }
  32.  
  33.     if(counterP>0){
  34.             float sredniaP = (float)sp/counterP;
  35.         printf("Srednia liczb parzystych to: %f \n", sredniaP);
  36.     } else {
  37.         printf("Brak liczb parzystych \n");
  38.     }
  39.  
  40.     return 0;
  41. }
Add Comment
Please, Sign In to add comment