Advertisement
jelyslime

testVankata

Jan 29th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double sumOfElemnets(double** arr, unsigned rows, unsigned collums)
  7. {
  8.     double sum = 0;
  9.  
  10.     for (int i = 0; i < rows; i++) {
  11.         for (int j = 0; j < collums; j++) {
  12.  
  13.             if (j % 2 != 0)
  14.             {
  15.                 sum = sum + arr[i][j];
  16.             }
  17.         }
  18.     }
  19.  
  20.     return sum;
  21. }
  22.  
  23. double avgSum(double** arr, unsigned rows, unsigned collums)
  24. {
  25.     int cnt = 0;
  26.     double sum = 0;
  27.  
  28.     for (int i = 0; i < rows; i++) {
  29.         for (int j = 0; j < collums; j++) {
  30.  
  31.             if (arr[i][j] < (-10))
  32.             {
  33.                 sum = sum + arr[i][j];
  34.                 cnt++;
  35.             }
  36.         }
  37.     }
  38.  
  39.     double resSum = sum / cnt;
  40.  
  41.     return resSum;
  42. }
  43.  
  44. int main() {
  45.  
  46.  
  47.     unsigned int rows, collums;
  48.  
  49.     cout << "Enter rows and collums and i will generate randum numbers for them" << endl;
  50.     cin >> rows >> collums;
  51.  
  52.     double* *dynamicarr = new double*[rows];
  53.  
  54.     for (unsigned int i = 0; i < rows; i++) {
  55.         dynamicarr[i] = new double[collums];
  56.     }
  57.  
  58.     double sumOfEl = sumOfElemnets(dynamicarr, rows, collums);
  59.     cout << "Sumata na elementite koito sa na nechetna kolona e: " << sumOfEl << endl;
  60.  
  61.     double avgEl = avgSum(dynamicarr, rows, collums);
  62.     cout << "Sredno aretmitichno na elementite po malki ot -10: " << avgEl << endl;
  63.  
  64.     for (int i = 0; i <= collums; i++) {
  65.         delete[] dynamicarr[i];
  66.     }
  67.  
  68.     delete[] dynamicarr;
  69.     dynamicarr = NULL;
  70.  
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement