Sort Values In Array
========================================================================
#include<iostream>
using namespace std;
main()
{
int arr[10]={50,10,30,60,90,40,80,70,20,100};
int n=10;
cout<<"Array Values Before Swaping\n";
for(int x=0;x<n-1;x++)
{
cout<<arr[x]<<" ";
}
cout<<endl<<endl;
for(int i=0;i<=n-1;i++)
{
for(int ptr=0;ptr<n-i;ptr++)
{
if(arr[ptr]>arr[ptr+1])
{
int temp;
temp=arr[ptr];
arr[ptr]=arr[ptr+1];
arr[ptr+1]=temp;
}
}
}
cout<<"Array value after Swaping\n";
for(int i=0;i<10;i++)
{
cout<<arr[i]<<" ";
}
}
using namespace std;
main()
{
int arr[10]={50,10,30,60,90,40,80,70,20,100};
int n=10;
cout<<"Array Values Before Swaping\n";
for(int x=0;x<n-1;x++)
{
cout<<arr[x]<<" ";
}
cout<<endl<<endl;
for(int i=0;i<=n-1;i++)
{
for(int ptr=0;ptr<n-i;ptr++)
{
if(arr[ptr]>arr[ptr+1])
{
int temp;
temp=arr[ptr];
arr[ptr]=arr[ptr+1];
arr[ptr+1]=temp;
}
}
}
cout<<"Array value after Swaping\n";
for(int i=0;i<10;i++)
{
cout<<arr[i]<<" ";
}
}
OutPut:
=======================================================================
0 comments:
Post a Comment