0
#include<iostream.h>
#include<conio.h>
int main()
{   int a[10],temp,bak;
    cout<<" enter the elements "<<endl;
    for(int i=0;i<5;i++)
    cin>>a[i];
    int m=a[0];
    for(int j=0;j<5;j++)
    {
       if(a[j]>a[j+1])
       {
             temp=a[j];
             a[j]=a[j+1];
             a[j+1]=temp;
       }  
       
                   
        
    }
    cout<<endl;
    for(int k=0;k<5;k++)
    {
         cout<<a[k]<<endl;
    }
    getch();
}
4
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by perniciosus
0

This Is The Right Code

#include<iostream>
using namespace std;
int main()
{ 
	int a[10],temp,i,j,m;
	cout<<" enter the elements "<<endl;
	for(i=0;i<5;i++)
		cin>>a[i];
	m=a[0];
	for(i=0;i<4;i++)
	{
		for(j=i+1;j<5;j++)
		{
			if(a[i]>a[j])
				{
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				} 
		}
	}
cout<<endl;
for(int k=0;k<5;k++)
{
cout<<a[k]<<endl;
}
return 0;
}
0

That's good, but why does a have 10 elements? :) And m isn't used, etc.

Didn't look in much detail..just removed the compilation errors...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.