You are on page 1of 3

#include<iostream.

h>
#include<process.h>>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#define k 4 //Here K defines the size of the
square matrix
void main()
{
int matrix[k][k];
int i,j,n;
int choice;
int Sr,Sc;
int maxld,maxrd;
int minld,minrd;
int Sld,Srd;
clrscr();
gotoxy(30,15);
cout<<"Cycle 1";
gotoxy(30,17);
cout<<"Program:1";
getch();
clrscr();
cout<<"Enter values in the table"<<endl<<endl; //inputt
ing the k*k matrix
for(i=0;i<k;i++)
for(j=0;j<k;j++)
{
cout<<"\tEnter the integer elements in ["<<i<<"]["<<j<<"]postion
"<<endl;
cin>>matrix[i][j];
}
do
{
clrscr();
gotoxy(12,10);
cout<<"M\tE\tN\tU"<<endl<<endl;
//Menu of the program
cout<<"\t1.Row sum and column sum of the array"<<endl<<endl;
cout<<"\t2.Upper and lower triangle"<<endl<<endl;
cout<<"\t3.Max and Min value along left and right diagonal"<<endl<<endl;
cout<<"\t4.Sum of values along the left and right diagonal"<<endl<<endl;
cout<<"\t5.Displaying the input Array"<<endl<<endl;
cout<<"\t6.Exit"<<endl<<endl;
cout<<"\t.Enter your choice";
cin>>choice;
clrscr();
switch(choice)
{
case 1:Sr=Sc=0;
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
Sr+=matrix[i][j];
Sc+=matrix[j][i];
}
cout<<"\n\nThe Sum of the Values in the row no "<<i+1<<" = "<<Sr
<<"\n\n\tThe Sum of the Values in the colum no "<<i+1<<" = "<<Sc<<endl;
Sr=Sc=0;
//This assignation is essential,as for each row(column) the sum should add up fr
om zero
}
break;
case 2:cout<<"The Upper Right Triangle and the Lower left Triangles are Displaye
d Below\n\n\t\t";
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
if(i==j)
//All the left diagonal elements are excluded from displaying,yielding 2 triangl
es
{
cout<<'\t';
continue;
}
cout<<matrix[i][j]<<'\t';
}
cout<<endl<<endl<<"\t\t";
}
cout<<"\n\nThe Upper Left Triangle and the Lower right Triangles are Disp
layed Below\n\n\t\t";
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
if(i+j==k-1)
//All the right diagonal elements are excluded from displaying,yielding 2 triang
les
{
cout<<'\t';
continue;
}
cout<<matrix[i][j]<<'\t';
}
cout<<endl<<endl<<"\t\t";
}
break;
case 3:maxld=matrix[0][0];
maxrd=matrix[0][k-1]; //IMPORT
ANT Here k-1 is taken instead of k,Since the size of the array is counted from 0
and not 1
minld=matrix[0][0];
minrd=matrix[0][k-1];
for(i=0;i<k;i++)
for(j=0;j<k;j++)
{
if(i==j)
//Checking left diagonal
{
if(matrix[i][j]>maxld)
maxld=matrix[i][j];
if(matrix[i][j]<minld)
minld=matrix[i][j];
}
if(i+j==k-1)
//Checking right diagonal
{
if(matrix[i][j]>maxrd)
maxrd=matrix[i][j];
if(matrix[i][j]<minrd)
minrd=matrix[i][j];
}
}
cout<<"The Biggest Number in the left diagonal = "<<maxld;
cout<<"\n\nThe Smallest Number in the left diagonal = "<<minld;
cout<<"\n\nThe Biggest Number in the right diagonal = "<<maxrd;
cout<<"\n\nThe Smallest Number in the right diagonal = "<<minrd<<endl;
break;
case 4:Sld=Srd=0;
for(i=0;i<k;i++)
for(j=0;j<k;j++)
{
if(i==j)
Sld+=matrix[i][j];
if(i+j==k-1)
Srd+=matrix[i][j];
}
cout<<"The Sum of the elements of the left diagonal = "<<Sld;
cout<<"\n\nThe Sum of the elements of the right diagonal = "<<Srd<<endl;
break;
case 5:for(i=0;i<k;i++)
{
gotoxy(20,15+(2*i));
for(j=0;j<k;j++)
cout<<matrix[i][j]<<'\t';
}
cout<<endl;
break;
case 6:exit(0);
break;
default:clrscr();
cout<<"Enter a valid choice(1-6)";
}
getch();
cout<<"\nDo You Want to continue(1/0) :";
cin>>n;
}while(n);
}

You might also like