Advertisement
Evilerus

Untitled

Dec 6th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #define N 100
  5.  
  6. int znajdz_max(int tab[], int ile_elementow, int *srednia) {
  7.   int i, c, suma, max;
  8.   max = tab[0];
  9.   c = 0;
  10.   suma = 0;
  11.   for (i=0; i<ile_elementow; i++) {
  12.     if (tab[i]>max) {
  13.       max = tab[i];
  14.     }
  15.     if (tab[i] < 140) {
  16.       suma = suma + tab[i];
  17.       c++;
  18.     }
  19.   }
  20.   suma = suma / c;
  21.   *srednia = suma;
  22.   return max;
  23. }
  24.  
  25. int main(void) {
  26.   int t[N];
  27.   int i;
  28.   int max, sr;
  29.   srand(time(NULL));
  30.   for (i=0; i<N; i++) {
  31.     t[i]=rand()%8192;
  32.   }
  33.   max = znajdz_max(t, N, &sr);
  34.   printf("maksymalna wartosc w tablicy = %d, srednia elementow ktore <140 = %d\n", max, sr);
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement