Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void z7_1()
- {
- int x;
- int iloscLiczbParzystych = 0;
- int iloscLiczbNieparzystych = 0;
- int sumaLiczbParzystych = 0;
- int sumaLiczbNieparzystych = 0;
- printf("Podaj ciag liczb zakonczony zerem: ");
- do {
- scanf("%d", &x);
- if (x != 0)
- {
- if (x%2 == 0)
- {
- iloscLiczbParzystych++;
- sumaLiczbParzystych += x;
- }
- else
- {
- iloscLiczbNieparzystych++;
- sumaLiczbNieparzystych+=x;
- }
- }
- } while(x != 0);
- if (iloscLiczbNieparzystych!=0)
- printf("Srednia liczb nieparzystych: %f\n", sumaLiczbNieparzystych/(float)iloscLiczbNieparzystych);
- if (iloscLiczbParzystych!=0)
- printf("Srednia liczb parzystych: %f\n", sumaLiczbParzystych/(float)iloscLiczbParzystych);
- }
- int z7_5()
- {
- int x;
- int max;
- int czyPodanaWartosc = 0;
- printf("Podaj ciag liczb zakonczony -1: ");
- do {
- scanf("%d", &x);
- if (x != -1)
- {
- if (!czyPodanaWartosc)
- {
- czyPodanaWartosc=1;
- max = x;
- continue;
- }
- if (max < x)
- max = x;
- }
- } while(x != -1);
- if (!czyPodanaWartosc)
- return -1;
- else
- return max;
- }
- int z8_2(int n)
- {
- int x;
- int nieParzyste = 0;
- printf("Podaj %d liczb: ", n);
- int i;
- for(i = 0; i<n; i++)
- {
- scanf("%d", &x);
- if (x%2 == 1)
- nieParzyste++;
- }
- return nieParzyste;
- }
- int z8_4(int n)
- {
- int x;
- int result = 1;
- if (n>=10)
- result = 0;
- printf("Podaj %d liczb: ", n);
- int i;
- for(i = 0; i<n; i++)
- {
- scanf("%d", &x);
- if (n>=10)
- result += x;
- else
- {
- if (i==0)
- continue;
- result *= x;
- }
- }
- return result;
- }
- int z8_42(int n)
- {
- int x;
- int result = 1;
- if (n>=10)
- result = 0;
- printf("Podaj %d liczb: ", n);
- int i;
- for(i = 0; i<n; i++)
- {
- scanf("%d", &x);
- if (n>=10)
- result += x;
- else
- {
- if (x > 5)
- result *= x;
- }
- }
- return result;
- }
- int z8_43(int * tab, int size)
- {
- int result = 1;
- if (n>=10)
- result = 0;
- printf("Podaj %d liczb: ", n);
- int i;
- for(i = 0; i<size; i++)
- {
- if (n>=10)
- result += tab[i];
- else
- {
- if (i==0)
- continue;
- result *= tab[i];
- }
- }
- return result;
- }
- int main()
- {
- z7_1();
- printf("Maksymalna liczba: %d\n", z7_5());
- int n;
- printf("Podaj ile liczb uzytkownik wpisze (do zad 8.2 i 8.4):");
- scanf("%d", &n);
- printf("Z8.2: %i\n", z8_2(n));
- printf("Z8.4: %i\n", z8_4(n));
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment