Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double sumOfElemnets(double** arr, unsigned rows, unsigned collums)
- {
- double sum = 0;
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < collums; j++) {
- if (j % 2 != 0)
- {
- sum = sum + arr[i][j];
- }
- }
- }
- return sum;
- }
- double avgSum(double** arr, unsigned rows, unsigned collums)
- {
- int cnt = 0;
- double sum = 0;
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < collums; j++) {
- if (arr[i][j] < (-10))
- {
- sum = sum + arr[i][j];
- cnt++;
- }
- }
- }
- double resSum = sum / cnt;
- return resSum;
- }
- int main() {
- unsigned int rows, collums;
- cout << "Enter rows and collums and i will generate randum numbers for them" << endl;
- cin >> rows >> collums;
- double* *dynamicarr = new double*[rows];
- for (unsigned int i = 0; i < rows; i++) {
- dynamicarr[i] = new double[collums];
- }
- double sumOfEl = sumOfElemnets(dynamicarr, rows, collums);
- cout << "Sumata na elementite koito sa na nechetna kolona e: " << sumOfEl << endl;
- double avgEl = avgSum(dynamicarr, rows, collums);
- cout << "Sredno aretmitichno na elementite po malki ot -10: " << avgEl << endl;
- for (int i = 0; i <= collums; i++) {
- delete[] dynamicarr[i];
- }
- delete[] dynamicarr;
- dynamicarr = NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement