You are on page 1of 4

#include <iostream>

using namespace std;

int main()
{
int array1[10][10], array2[10][10];
int i, j, k, a, m, n;

cout<<"Enter the order of the matrix \n";


cin>>n;
cout<<"Enter co-efficients of the matrix \n";
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
cin>>array1[i][j];
}
}

for (i = 0; i < n; ++i)


{
for (j = 0; j < n; ++j)
{
for (k =j+1; k < n; ++k)
{
if (array1[i][j] > array1[i][k])
{
a = array1[i][j];
array1[i][j] = array1[i][k];
array1[i][k] = a;
}
}
}
}
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
cout<< array1[i][j]<<" ";
}
cout<<endl;
} return 0;
}
#include <iostream>
using namespace std;

int main() {
int a[20][20];
int temp[20][20];
int n, i, j, l, k;

cout << "Enter the matrix size: ";


cin >> n;
cout << "Enter the matrix values: " << endl;
for (j = 0; j < n; j++) {
for (i = 0; i < n; i++) {
cin >> a[j][i];
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (l = i; l < n; l++) {
if (l == i) {
for (k = (j + 1); k < n; k++) {
if (a[i][j] > a[l][k]) {
temp[i][j] = a[i][j];
a[i][j] = a[l][k];
a[l][k] = temp[i][j];
}
} } } }}
if (l > i) {
for (k = 0; k < n; k++) {
if (a[i][j] > a[l][k]) {
temp[i][j] = a[i][j];
a[i][j] = a[l][k];
a[l][k] = temp[i][j];
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; i++) {
cout << a[i][j];
}
}
cout << endl;

return 0;

#include <iostream>

using namespace std;

void order(int &x, int &y){

int temp=x;

x=y;

y=temp;

}
int main() {

int n,x;

int My [20][20];

cout<<"Enter a value for square matrix:";

cin>>n;

cout<<"Enter elements of matrix:";

for(int i=0; i<n; i++) {

for(int j=0; j<n; j++) {

cin>>My[i][j];

for( int k=0; k<n; k++){

for(int m=0; m<n; m++){

x=m+1;

for(int i=k; i<n; i++){

for(int j=x;j<n; j++){

if(My[k][m]>My[i][j]) {

order(My[k][m],My[i][j]);

x=0;

for(int i=0; i<n;i++) {

for(int j=0; j<n; j++){

cout<<My[i][j]<<" ";
}

cout<<endl;

return 0;

You might also like