ifinox

PP 24.10.2017

Oct 24th, 2017
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. void z7_1()
  7. {
  8.     int x;
  9.     int iloscLiczbParzystych = 0;
  10.     int iloscLiczbNieparzystych = 0;
  11.     int sumaLiczbParzystych = 0;
  12.     int sumaLiczbNieparzystych = 0;
  13.     printf("Podaj ciag liczb zakonczony zerem: ");
  14.     do {
  15.         scanf("%d", &x);
  16.         if (x != 0)
  17.         {
  18.             if (x%2 == 0)
  19.             {
  20.                 iloscLiczbParzystych++;
  21.                 sumaLiczbParzystych += x;
  22.             }
  23.             else
  24.             {
  25.                 iloscLiczbNieparzystych++;
  26.                 sumaLiczbNieparzystych+=x;
  27.             }
  28.         }
  29.     } while(x != 0);
  30.     if (iloscLiczbNieparzystych!=0)
  31.         printf("Srednia liczb nieparzystych: %f\n", sumaLiczbNieparzystych/(float)iloscLiczbNieparzystych);
  32.     if (iloscLiczbParzystych!=0)
  33.         printf("Srednia liczb parzystych: %f\n", sumaLiczbParzystych/(float)iloscLiczbParzystych);
  34.  
  35. }
  36.  
  37. int z7_5()
  38. {
  39.     int x;
  40.     int max;
  41.  
  42.     int czyPodanaWartosc = 0;
  43.     printf("Podaj ciag liczb zakonczony -1: ");
  44.     do {
  45.         scanf("%d", &x);
  46.         if (x != -1)
  47.         {
  48.             if (!czyPodanaWartosc)
  49.             {
  50.                 czyPodanaWartosc=1;
  51.                 max = x;
  52.                 continue;
  53.             }
  54.             if (max < x)
  55.                 max = x;
  56.         }
  57.     } while(x != -1);
  58.     if (!czyPodanaWartosc)
  59.         return -1;
  60.     else
  61.         return max;
  62. }
  63.  
  64. int z8_2(int n)
  65. {
  66.     int x;
  67.     int nieParzyste = 0;
  68.     printf("Podaj %d liczb: ", n);
  69.     int i;
  70.     for(i = 0; i<n; i++)
  71.     {
  72.         scanf("%d", &x);
  73.         if (x%2 == 1)
  74.             nieParzyste++;
  75.     }
  76.     return nieParzyste;
  77. }
  78.  
  79. int z8_4(int n)
  80. {
  81.     int x;
  82.     int result = 1;
  83.     if (n>=10)
  84.         result = 0;
  85.  
  86.     printf("Podaj %d liczb: ", n);
  87.     int i;
  88.     for(i = 0; i<n; i++)
  89.     {
  90.         scanf("%d", &x);
  91.         if (n>=10)
  92.             result += x;
  93.         else
  94.         {
  95.             if (i==0)
  96.                 continue;
  97.             result *= x;
  98.         }
  99.  
  100.     }
  101.     return result;
  102. }
  103.  
  104. int z8_42(int n)
  105. {
  106.     int x;
  107.     int result = 1;
  108.     if (n>=10)
  109.         result = 0;
  110.  
  111.     printf("Podaj %d liczb: ", n);
  112.     int i;
  113.     for(i = 0; i<n; i++)
  114.     {
  115.         scanf("%d", &x);
  116.         if (n>=10)
  117.             result += x;
  118.         else
  119.         {
  120.             if (x > 5)
  121.                 result *= x;
  122.         }
  123.  
  124.     }
  125.     return result;
  126. }
  127.  
  128. int z8_43(int * tab, int size)
  129. {
  130.     int result = 1;
  131.     if (n>=10)
  132.         result = 0;
  133.  
  134.     printf("Podaj %d liczb: ", n);
  135.     int i;
  136.     for(i = 0; i<size; i++)
  137.     {
  138.         if (n>=10)
  139.             result += tab[i];
  140.         else
  141.         {
  142.             if (i==0)
  143.                 continue;
  144.             result *= tab[i];
  145.         }
  146.  
  147.     }
  148.     return result;
  149. }
  150.  
  151. int main()
  152. {
  153.     z7_1();
  154.  
  155.     printf("Maksymalna liczba: %d\n", z7_5());
  156.  
  157.     int n;
  158.     printf("Podaj ile liczb uzytkownik wpisze (do zad 8.2 i 8.4):");
  159.     scanf("%d", &n);
  160.     printf("Z8.2: %i\n", z8_2(n));
  161.     printf("Z8.4: %i\n", z8_4(n));
  162.  
  163.  
  164.  
  165.     system("PAUSE");
  166.  
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment