In row swap operation the rows of the matrix is swaped.............
i.e., the rows are interchanged................
Program:
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
int main()
{
system("cls");
system("color a0");
cout<<setw(54)<<"*****---------------------*****\n";
cout<<setw(54)<<"*****SWAP ROWS OF A MATRIX*****\n";
cout<<setw(54)<<"*****---------------------*****\n";
cout<<"\n\n";
int a[100][100],i,j,m,n;
cout<<"\tEnter number of rows : ";
cin>>m;
cout<<"\tEnter number of columns : ";
cin>>n;
cout<<"\n\n\tEnter the matrix : \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<"\tEnter ["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
cout<<"\n\n\t\t\tProcessing......";
Sleep(2200);
system("cls");
system("color f0");
cout<<"\n\n\n\t\t\tThe matrix is : \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<m/2;++i)
{
int p=m-1;
for(j=0;j<n;++j)
{
int temp=a[i][j];
a[i][j]=a[p][j];
a[p][j]=temp;
}
--p;
}
cout<<"\n\n\t\t\tThe swaped matrix is : \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Output:
i.e., the rows are interchanged................
Program:
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
int main()
{
system("cls");
system("color a0");
cout<<setw(54)<<"*****---------------------*****\n";
cout<<setw(54)<<"*****SWAP ROWS OF A MATRIX*****\n";
cout<<setw(54)<<"*****---------------------*****\n";
cout<<"\n\n";
int a[100][100],i,j,m,n;
cout<<"\tEnter number of rows : ";
cin>>m;
cout<<"\tEnter number of columns : ";
cin>>n;
cout<<"\n\n\tEnter the matrix : \n\n";
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
cout<<"\tEnter ["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
cout<<"\n\n\t\t\tProcessing......";
Sleep(2200);
system("cls");
system("color f0");
cout<<"\n\n\n\t\t\tThe matrix is : \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<m/2;++i)
{
int p=m-1;
for(j=0;j<n;++j)
{
int temp=a[i][j];
a[i][j]=a[p][j];
a[p][j]=temp;
}
--p;
}
cout<<"\n\n\t\t\tThe swaped matrix is : \n\n";
for(i=0;i<m;++i)
{
cout<<"\t\t\t";
for(j=0;j<n;++j)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Output:
0 comments:
Post a Comment