#include<iostream>
using namespace std;
int main()
{
int n, i, j, k;
cout << "Enter Array Element Number :: ";
cin >> n;
cout << endl;
int a[n];
cout << "Enter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
}
cout << endl;
for(i=1;i<n;i++)
{
k = a[i];
j = i-1;
while(j>=0 && a[j] > k)
{
a[j+1] = a[j];
j--;
}
a[j+1] = k;
}
cout << "Ascending Order :: ";
for(i=0;i<n;i++)
{
cout << a[i] << " ";
}
cout << endl;
return 0;
}
using namespace std;
int main()
{
int n, i, j, k;
cout << "Enter Array Element Number :: ";
cin >> n;
cout << endl;
int a[n];
cout << "Enter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
}
cout << endl;
for(i=1;i<n;i++)
{
k = a[i];
j = i-1;
while(j>=0 && a[j] > k)
{
a[j+1] = a[j];
j--;
}
a[j+1] = k;
}
cout << "Ascending Order :: ";
for(i=0;i<n;i++)
{
cout << a[i] << " ";
}
cout << endl;
return 0;
}
Comments
Post a Comment