You are on page 1of 2

#include<iostream>

#include<stdlib.h>
using namespace std;
int main(void)
{
int op,i,j,k,l,r=0,c=0,sum=0,coun=0,temp=0;
char ch;
cout<<"Input the number of rows ";
cin>>r;
cout<<"Input the number of columns ";
cin>>c;
int *a = new int[r*c];
cout<<"Enter elements ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i*c+j];
}
}
do
{
system("cls");
cout<<"1. Display Array\n2. Sum of diagonal elements\n3. Display duplica
te elements\n4. Exit";
cin>>op;
switch(op)
{
case 1:
system("cls");
cout<<"The array is\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i*c+j];
}
cout<<"\n";
}
cin>>ch;
break;
case 2:
system("cls");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
sum += a[i*c+j];
}
}
cout<<"Sum of diagonals "<<sum;
cin>>ch;
break;
case 3:
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)

{
temp= a[i*c+j];
for(k=i;k<r;k++)
{
for(l=j;l<c;l++)
{
if(temp== a[k*c+l])
coun++;
}
}
if(coun>1)
cout<<temp<<" is duplicate\n";
coun=0;
}
}
cin>>ch;
break;
}
}while(op!=4);
}

You might also like