Friday, 7 November 2014

Write a C++ Program illustrating to sort integer numbers.

#include <iostream.h>
void main(void)
{
int t,i,j;

int n;

cout<<"Enter the number of values to be sorted ";

cin>>n;

int s[20];

cout<<"\nEnter  values ";

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

cin>>s[i];

cout<<endl;

cout<<"sorted list is ";

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

{

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

{

if (s[j]>s[j+1])

{

t=s[j+1];

s[j+1]=s[j];

s[j]=t;

}

}

cout<<endl;

cout<<"Pass "<<i+1<<" ";

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

cout<<s[k]<<" ";

}

cout<<endl;

}

1 comment: