Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[4][4], row ,col,r_d=0,l_d=0;
- for(col=0;col<4; col++){
- for (row=0;row<4;row++){
- cout<<"enter the "<<col<<" x "<<row<<" enter :";
- cin>> arr[col][row];
- }
- }
- cout<<"the 4x4 matrix enter by the user :"<< endl;
- for(col=0;col<4; col++){
- cout<<endl;
- for (row=0;row<4;row++){
- cout<<setw(4)<<arr[col][row];
- }
- }
- cout<<endl;
- for(col=0;col<4; col++){
- cout<<endl;
- for (row=0;row<4;row++){
- if(col==row){
- r_d=r_d + arr[col][row];
- cout<<arr[col][row]<<" ";
- }
- }
- }
- cout<<endl;
- cout<<" right diagonal : "<<r_d;
- cout<<endl;
- int s=3;
- for(col=0;col<4; col++){
- cout<<endl;
- for (row=0;row<4;row++){
- if(row==s){
- l_d=l_d + arr[col][row];
- cout<<arr[col][row]<<" ";
- }
- }
- s--;
- }
- cout<<endl;
- cout<<" left diagonal : "<<l_d;
- cout<<endl;
- cout<<"sum of diagonals : "<<r_d+l_d;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement