#include #include using namespace std; int main() { int n, sum = 0; cout << "Enter the size of square matrix" << endl; cin >> n; int aar[20][20]; cout << "Enter the element of matrix" << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> aar[i][j]; } } for (int i = 0; i < n; i++) { sum = 0; for (int j = 0; j < n; j++) { sum += aar[j][i]; } aar[n][i] = sum; cout << endl; } for (int i = 0; i < n; i++) { sum = 0; for (int j = 0; j < n; j++) { sum += aar[i][j]; } aar[i][n] = sum; cout << endl; } sum = 0; for (int i = 0; i < n; i++) { sum += aar[n][i]; } aar[n][n] = sum; cout << "Resultant Matrix :- " << endl; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << aar[i][j] << " "; } cout << endl; } return 0; }
Enter the size of square matrix 3 Enter the element of matrix 2 2 2 1 1 1 3 3 3 Resultant Matrix :- 2 2 2 6 1 1 1 3 3 3 3 9 6 6 6 18
0 Comments