#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();
}
sahil_logic
0
Light Poster
Recommended Answers
Jump to PostThis 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; }
Jump to PostThat's good, but why does a have 10 elements? :) And m isn't used, etc.
All 5 Replies
SpS
34
Posting Pro
dwks
149
Posting Whiz in Training
SpS
34
Posting Pro
dwks
149
Posting Whiz in Training
perniciosus
19
Junior Poster in Training
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.