Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (int i = 0; i < columnLength; i++) {
- for (int j = 0; j < rowLength; j++) {
- int up = i + 1;
- if (up == columnLength) {
- up = 0;
- }
- int down = i - 1;
- if (down < 0) {
- down = columnLength - 1;
- }
- int right = j + 1;
- if (right == rowLength) {
- right = 0;
- }
- int left = j - 1;
- if (left < 0) {
- left = rowLength - 1;
- }
- matrix2[i][j] = matrix1[up][j] + matrix1[down][j] + matrix1[i][right] + matrix1[i][left];
- }
- }
- /* print matrix2 ,
- Sample Input:
- 9 5 3
- 0 7 -1
- -5 2 9
- Sample Output:
- 3 21 22
- 10 6 19
- 20 16 -1 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement