Write a menu driven program for the following operations on 2-d array of 3*3 elements:
a) sort the data row wise
b) sum of diagonals
c) sum of elements except diagonals
d) transpose the matrix
e) multiplication of matrix
f) additon of matrix
g) display perfect numbers of each column
h) display prime numbers of each row
i) display max digit of each row
j) sort the data column wise
#include<iostream>
using namespace std;
int main(){
int matrix[3][3];
for(int i=0;i<=2;++i){
for(int j=0;j<=2;++j){
cout<<"Enter matrix"<<endl;
cin>>matrix[i][j];
}
}
int sum=0;
for( int j=0;j<=2;++j){
sum=sum+matrix[i][i];
}
cout<<"sum of diagonials"<<sum<<endl;
int sum1=0;
for( i=0;i<=2;++i){
for(int j=0;j<=2;++j){
sum1=sum1+matrix[i][j];
}
}
cout<<"sum without diagonials"<<sum1-sum<<endl;
for( i=0;i<=2;++i){
for(int j=0;j<=2;++j){
cout<<matrix[i][j]<<endl;
}
}
return 0;}
Comments
Leave a comment