Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- int main(int argc, char * argv[]) {
- int n;
- scanf("%d", &n);
- int mat[n][n];
- int b[n][n];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- scanf("%d", &mat[i][j]);
- b[i][j] = mat[i][j];
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- if(i + j == n - 1) {
- int sum = 0;
- for(int j2 = 0; j2 < n; j2++) {
- if(j2 > j) {
- sum += mat[i][j2];
- }
- }
- for(int i2 = 0; i2 < n; i2++) {
- if(i2 > i) {
- sum += mat[i2][j];
- }
- }
- b[i][j] = sum;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- printf("%d ", b[i][j]);
- }
- printf("\n");
- }
- }
- /*
- 3
- 1 2 3
- 4 5 6
- 7 8 9
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement