Skip to content

Instantly share code, notes, and snippets.

@kostyakoz
Created February 25, 2015 19:43
Show Gist options
  • Save kostyakoz/c569fa8dcbf06f54c865 to your computer and use it in GitHub Desktop.
Save kostyakoz/c569fa8dcbf06f54c865 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char const *argv[]) {
srand(time(0));
int n, m;
cout << "Input n (str num) and m (col num): ";
cin >> n;
cin >> m;
int ** array = new int *[n];
for (int i = 0; i < n; i++) array[i] = new int[m];
cout << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
array[i][j] = rand() % (9 - 1 + 1) + 1;
cout << array[i][j] << " ";
}
cout << "\n";
}
cout << "\n***** RESULT *****\n\n";
int ** plus = new int *[n];
for (int i = 0; i < n; i++) plus[i] = new int[m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
plus[i][j] = 0;
for (int e = 0; e <= i; e++) {
for (int k = 0; k <= j; k++) {
plus[i][j] = plus[i][j] + array[e][k];
}
}
cout << plus[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment