Advertisement
Josif_tepe

Untitled

Jun 10th, 2024
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5.  
  6. int sredna(int *niza, int n) {
  7.     int brojac = 0;
  8.     for(int i = 0; i < n; i++) {
  9.         int element = abs(niza[i]);
  10.         int prosek = 0;
  11.         for(int j = 0; j < element; j++) {
  12.             int x;
  13.             scanf("%d", &x);
  14.             brojac++;
  15.  
  16.             prosek += x;
  17.         }
  18.         prosek /= element;
  19.         niza[i] = prosek;
  20.  
  21.     }
  22.     return brojac;
  23. }
  24. int main(int argc, char * argv[]) {
  25.     int n;
  26.     scanf("%d", &n);
  27.  
  28.     int niza[n];
  29.     for(int i = 0; i < n; i++) {
  30.         scanf("%d", &niza[i]);
  31.     }
  32.     int result = sredna(niza, n);
  33.     printf("%d\n", result);
  34.  
  35.     for(int i = 0; i < n; i++) {
  36.         printf("%d ", niza[i]);
  37.     }
  38.    
  39.    
  40. }
  41.  
  42.  
  43. /*
  44. 5
  45. 1 2 3 4 5
  46.  
  47. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement