Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

C++ Code for Sorting 2D Array odd rows asscending and Even Rows Decending

#include<iostream>
using namespace std;
void sortass(int [][4],int);
void sortdes(int [][4],int);
void main()
{
int arr[6][4];
for(int i=0;i<6;i++)
for(int j=0;j<4;j++)
arr[i][j]=rand()%40+10;
for(int i=0;i<6;i++)
{
for(int j=0;j<4;j++)
cout<<arr[i][j]<<" ";
cout<<"\n";
}
cout<<"\n";
for(int i=0;i<6;i++)
{
if(i%2==0)
{
sortass(arr,i);
}
if(i%2!=0)
{
sortdes(arr,i);
}
}
for(int i=0;i<6;i++)
{
for(int j=0;j<4;j++)
cout<<arr[i][j]<<" ";
cout<<"\n";
}
}
void sortdes(int arr[][4],int i)
{
int temp;
for(int k=0;k<4;k++)
{
for(int j=k;j<4;j++)
{
if(arr[i][k]<arr[i][j])
{
temp=arr[i][j];
arr[i][j]=arr[i][k];
arr[i][k]=temp;
}
}
}

}
void sortass(int arr[][4],int i)
{
int temp;
for(int k=0;k<4;k++)
{
for(int j=k;j<4;j++)
{
if(arr[i][k]>arr[i][j])
{
temp=arr[i][j];
arr[i][j]=arr[i][k];
arr[i][k]=temp;
}
}
}
}

No comments: