#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();
}

Recommended Answers

All 5 Replies

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;
}

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

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...

I see. BTW, it should have 5 elements.

IMO "debug my code" is not a question...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.