Ascending And Descending in Array
Logical C++ Program
In this program Half Values of array are in Ascending Order and Half Values are in Descending Order...
========================================================================
#include<iostream>
using namespace std;
main()
{
int arr[10],min;
cout<<"Enter Values in Array\n";
for(int i=0;i<10;i++)
{
cin>>arr[i];
}
cout<<"Values in Array\n";
for(int i=0;i<10;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
for(int i=1;i<=5;i++)
{
for(int j=0;j<5-i;j++)
{
if(arr[j]>arr[j+1])
{
swap(arr[j],arr[j+1]);
}
}
}
for(int i=6;i<=10;i++)
{
for(int j=5;j<11;j++)
{
if(arr[j]<arr[j+1])
{
swap(arr[j],arr[j+1]);
}
}
}
for(int i=0;i<5;i++)
{
cout<<arr[i]<<" ";
}
for(int i=6;i<=10;i++)
{
cout<<arr[i]<<" ";
}
}
OutPut:
========================================================================
Code By: Kabeer Hussain
0 comments:
Post a Comment