Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// Two Dimensional Array
#include<iostream>
using namespace std;
int main()
{
system("cls");
int arr[50][50],m,n;
int r,c;
cout<<"Enter value of row";
cin>>m;
cout<<"Enter value of column";
cin>>n;
cout<<"Enter elements in matrics:";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cin>>arr[r][c];
}
}
cout<<"Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr[r][c]<<" ";
}
cout<<endl;
}
cout<<"Digonal Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
if(r==c)
cout<<arr[r][c]<<" ";
}
cout<<endl;
}
cout<<"Lower Triangle Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
if(r>=c)
cout<<arr[r][c]<<" ";
}
cout<<endl;
}
cout<<"Upper Triangle Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
if(r<=c)
cout<<arr[r][c]<<" ";
}
cout<<endl;
}
return 0;
}
/*
a[0][0] 9
a[0][1] 45
a[0][2] 13
a[1][0] 78
a[1][1] 13
a[1][2] 77
a[2][0] 90
a[2][1] 34
a[2][2] 67
*/