#include<iostream>
using namespace std;
//this program gives the sum or *plication of entities of diagonal entries of 2d array
int main()
{
const int row=5;
const int col=5;
//5x5 matrix
int arr[row][col];
//inputting values
for(int r_index=0;r_index<row;r_index++)
{
for(int c_index=0;c_index<row;c_index++)
{
cout<<"Enter the value at ["<<r_index<<"]["<<c_index<<"] th index : ";
cin>>arr[r_index][c_index];
}
}
int sum_diag=0;
int multi_diag=0;
cout<<endl;
char op;
cout<<"Enter the op to be performed(+ and * only) : ";
cin>>op;
if(op=='+')
{
for(int i=0;i<row;i++)
{
for(int j=0;j<row;j++)
{
if(i==j)
{
sum_diag = sum_diag + arr[i][j];
}
}
}
cout<<endl;
cout<<"The Sum of Diagnal Enteries is : "<<sum_diag<<endl;
if(sum_diag%2==0)
{
cout<<endl;
cout<<"The Sum of diagnal enteries is EVEN ."<<endl;
}
else
{
cout<<endl;
cout<<"The Sum of diagnal enteries is ODD ."<<endl;
}
}
else if(op=='*')
{
for(int i=0;i<row;i++)
{
for(int j=0;j<row;j++)
{
if(i==j)
{
multi_diag = multi_diag * arr[i][j];
}
}
}
cout<<endl;
cout<<"The Multiplication of Diagnal Enteries is : "<<multi_diag<<endl;
if(multi_diag%2==0)
{
cout<<endl;
cout<<"The Multiplication of diagnal enteries is EVEN ."<<endl;
}
else
{
cout<<endl;
cout<<"The Multiplicaton of diagnal enteries is ODD ."<<endl;
}
}
else
{
cout<<endl;
cout<<"Invalid Operation performed"<<endl;
}
cout<<endl;
return 0;
}
<by moeed>
using namespace std;
//this program gives the sum or *plication of entities of diagonal entries of 2d array
int main()
{
const int row=5;
const int col=5;
//5x5 matrix
int arr[row][col];
//inputting values
for(int r_index=0;r_index<row;r_index++)
{
for(int c_index=0;c_index<row;c_index++)
{
cout<<"Enter the value at ["<<r_index<<"]["<<c_index<<"] th index : ";
cin>>arr[r_index][c_index];
}
}
int sum_diag=0;
int multi_diag=0;
cout<<endl;
char op;
cout<<"Enter the op to be performed(+ and * only) : ";
cin>>op;
if(op=='+')
{
for(int i=0;i<row;i++)
{
for(int j=0;j<row;j++)
{
if(i==j)
{
sum_diag = sum_diag + arr[i][j];
}
}
}
cout<<endl;
cout<<"The Sum of Diagnal Enteries is : "<<sum_diag<<endl;
if(sum_diag%2==0)
{
cout<<endl;
cout<<"The Sum of diagnal enteries is EVEN ."<<endl;
}
else
{
cout<<endl;
cout<<"The Sum of diagnal enteries is ODD ."<<endl;
}
}
else if(op=='*')
{
for(int i=0;i<row;i++)
{
for(int j=0;j<row;j++)
{
if(i==j)
{
multi_diag = multi_diag * arr[i][j];
}
}
}
cout<<endl;
cout<<"The Multiplication of Diagnal Enteries is : "<<multi_diag<<endl;
if(multi_diag%2==0)
{
cout<<endl;
cout<<"The Multiplication of diagnal enteries is EVEN ."<<endl;
}
else
{
cout<<endl;
cout<<"The Multiplicaton of diagnal enteries is ODD ."<<endl;
}
}
else
{
cout<<endl;
cout<<"Invalid Operation performed"<<endl;
}
cout<<endl;
return 0;
}
<by moeed>
No comments:
Post a Comment