Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- int main(int argc, const char * argv[])
- {
- int n;
- scanf("%d", &n);
- int mat1[n][n];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- scanf("%d", &mat1[i][j]);
- }
- }
- int m;
- scanf("%d", &m);
- int mat2[m][m];
- for(int i = 0; i < m; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &mat2[i][j]);
- }
- }
- int pom;
- if(n < m) {
- pom = n;
- }
- else {
- pom = m;
- }
- for(int i = 0; i < pom; i++) {
- if(mat1[i][i] == mat2[i][i]) {
- int sum1 = 0;
- for(int j = i + 1; j < n; j++) {
- sum1 += mat1[i][j];
- }
- mat1[i][i] = sum1;
- int sum2 = 0;
- for(int j = i + 1; j < m; j++) {
- sum2 += mat2[i][j];
- }
- mat2[i][i] = sum2;
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- printf("%d ", mat1[i][j]);
- }
- printf("\n");
- }
- for(int i = 0; i < m; i++) {
- for(int j = 0; j < m; j++) {
- printf("%d ", mat2[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
- /*
- 3
- 5 7 3
- 8 6 7
- 9 9 9
- 5
- 10 2 1 1 1
- 4 6 3 2 0
- 5 2 9 7 1
- 6 5 4 18 2
- 2 16 15 9 10
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement