bubble sort. any ideas?

Problem Statement:
Design a program in C/C++ that will sort four(4) numbers. The four numbers must be inputs coming from a user. Then, the program must sort the four(4) numbers using bubble sort in
(a) Ascending order
(b) Descending order

---------------------------------end of problem statement----------------------------------

e.g. for example:
Enter First number : 10
Enter Second number : 5
Enter Third number : 235
Enter Fourth number : 89
Ascending order : 5 10 89 235
Descending order : 235 89 10 5
Post the code you've got so far.
i have the code. =) .. done

For Loops

#include<iostream>
#include<conio.h>
using namespace std;
main(void){
long a,b,num,res,x;
a=1;
b=0;
cout<<"enter what series to stop: ";
cin>>num;
cout<<"the fibonacci series is: \n";
for(x=0;x<num;x++){
cout<<b<<" ";
res=a+b;
a=b;
b=res;
}
getch();
return 0;
}

Do-while loop

#include<conio.h>
#include<iostream>
using namespace std;
main (void){
long a,b,num,res,x;
a=1;
b=0;
x=a;
cout<<"enter what series to stop: ";
cin>>num;
cout<<"the fibonacci series is: \n";
do{
res=a+b;
a=b;
b=res;
cout<<a<<" ";
x++;
}while(x<=num);

getch();
return 0;
}

While loop

#include<conio.h>
#include<iostream>
using namespace std;
main (void){
long a,b,num,res,x;
a=1;
b=0;
x=a;
cout<<"enter what series to stop: ";
cin>>num;
cout<<"the fibonacci series is: \n";

while(x<=num){
res=a+b;
a=b;
b=res;
cout<<a<<" ";
x++;
}
getch();
return 0;
}
Topic archived. No new replies allowed.