Advertisement
RicoHeartless

LABA 6.1

May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. double func(int arr[]){
  7.     int sum = 0;
  8.     double nepara = 0;
  9.     int k(0);// вказує на к-сть непарних елементів.
  10.     for (int z(0); z < 10; z++){
  11.         if (arr[z] % 2 != 0){ sum += arr[z]; k++; }// сумую непарні елементи
  12.     }
  13.     if (k == 0) exit(0);
  14.     else {
  15.         nepara = sum / k;
  16.         return nepara;
  17.     }
  18. }
  19. double input(){
  20.     int const N = 10;
  21.     static int mas[N]{};
  22.     cout << "Enter data to array: " << endl;
  23.     for (int i(0); i < N; i++){
  24.         cout << "Enter [" << i << "]: ";
  25.         cin >> mas[i];
  26.     }
  27.     return func(mas);
  28. }
  29. void output(double x){
  30.     cout << "arithmetic mean is: " << x << endl;
  31. }
  32.  
  33. void main(){
  34.     output(input());
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement