| | |
print out number in ascending order in c++ WITHOUT USING ARRAY AND FUNCTION
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 10
Reputation:
Solved Threads: 0
hello, i'm newbie here and also in programming world. so I would to request help from pros here. my question is, how to print out number entered in random in ascending order WITHOUT USING ARRAY AND FUNCTION? let say the user key in 4, 56, 31, 90, 11 and the output would be 4, 11, 31, 56, 90. hope anyone would help me.
thank you.
thank you.
0
#2 Nov 12th, 2009
1) Why ?
2) need compile time variable meaning there will be a fixed amount
of inputs to get
3) Need to implement your own sorting method and use it inside main,
so technically it won't be a function. If not then you will need a lot
of if/else or you can use trees.
4) Bad Idea.
2) need compile time variable meaning there will be a fixed amount
of inputs to get
3) Need to implement your own sorting method and use it inside main,
so technically it won't be a function. If not then you will need a lot
of if/else or you can use trees.
4) Bad Idea.
Go ahead and try to solve this euler problem, if u can. Check with me for hints and answers. Good Luck Solved by:tux4life, zalezog, "your name here";
•
•
Join Date: Oct 2009
Posts: 82
Reputation:
Solved Threads: 1
0
#3 Nov 12th, 2009
din....
more or less you have to use lots of if else...
but this is suitable only if you get fixed number of input..
let say that you ask the user to enter only 3 numbers only..
by manipulating the input using if else statement,you could sorting them
in the way you like...
consider this example of program that sorting the numbers user entered in ascending or decending order...
more or less you have to use lots of if else...
but this is suitable only if you get fixed number of input..
let say that you ask the user to enter only 3 numbers only..
by manipulating the input using if else statement,you could sorting them
in the way you like...
consider this example of program that sorting the numbers user entered in ascending or decending order...
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main () { int a,b,c; cout<<"Enter three integers :"; cin>>a>>b>>c; cout<<endl; if (a>b && b>c) { cout<<c<<" "<<b<<" "<<a; } else if (a>c && c>b) cout<<b<<" "<<c<<" "<<a; else if (b>a && a>c) cout<<c<<" "<<a<<" "<<b; else if (b>c && c>a) cout<<a<<" "<<c<<" "<<b; else if (c>a && a>b) cout<<b<<" "<<a<<" "<<c; else cout<<a<<" "<<b<<" "<<c; cout<<endl; if (a>b && b>c) { cout<<a<<" "<<b<<" "<<c; } else if (a>c && c>b) cout<<a<<" "<<c<<" "<<b; else if (b>a && a>c) cout<<b<<" "<<a<<" "<<c; else if (b>c && c>a) cout<<b<<" "<<c<<" "<<a; else if (c>a && a>b) cout<<c<<" "<<a<<" "<<b; else cout<<c<<" "<<b<<" "<<a; }
•
•
Join Date: Nov 2009
Posts: 10
Reputation:
Solved Threads: 0
1
#6 Nov 16th, 2009
I still cant figure out with 5 input number..! is there anything wrong with my coding..??
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main () { int a, b, c, d, e; int v, w, x, y, z; cout << "Enter Five Number: "; cin >> a >> b >> c >> d >> e; if ( a < b && a < c && a < d && a < e) { a = v; } else if ( a > b && a < c && a < d && a < e ) { a = w; } else if ( a > b && a > c && a < d && a < e ) { a = x; } else if ( a > b && a > c && a > d && a < e ) { a = y; } else if ( a > b && a > c && a > d && a > e ) { a = z; } else if ( b < a && b < c && b < d && b < e ) { b = v; } else if ( b > a && b < c && b < d && b < e ) { b = w; } else if ( b > a && b > c && b < d && b < e ) { b = x; } else if ( b > a && b > c && b > d && b < e ) { b = y; } else if ( b > a && b > c && b > d && b > e ) { b = z; } else if ( c < a && c < b && c < d && c < e ) { c = v; } else if ( c > a && c < b && c < d && c < e ) { c = w; } else if ( c > a && c > b && c < d && c < e ) { c = x; } else if ( c > a && c > b && c > d && c < e ) { c = y; } else if ( c > a && c > b && c > d && c > e ) { c = z; } else if ( d < a && d < b && d < c && d < e ) { d = v; } else if ( d > a && d < b && d < c && d < e ) { d = w; } else if ( d > a && d > b && d < c && d < e ) { d = x; } else if ( d > a && d > b && d > c && d < e ) { d = y; } else if ( d > a && d > b && d > c && d > e ) { d = z; } else if ( e < a && e < b && e < c && e < d ) { e = v; } else if ( e > a && e < b && e < c && e < d ) { e = w; } else if ( e > a && e > b && e < c && e < d ) { e = x; } else if ( e > a && e > b && e > c && e < d ) { e = y; } else if ( e > a && e > b && e > c && e > d ) { e = z; } cout << "Your Number Are: " << v << " " << w << " " << x << " " << y << " " << z; return 0; }
0
#7 Nov 16th, 2009
Yes, your if/else is incorrect, only 1 of them gets evaluated.
Go ahead and try to solve this euler problem, if u can. Check with me for hints and answers. Good Luck Solved by:tux4life, zalezog, "your name here";
•
•
Join Date: Oct 2009
Posts: 82
Reputation:
Solved Threads: 1
0
#8 Nov 16th, 2009
okeyh...
Its look like you still not getting the idea...
Sorry for saying this,but your code its completely wrong if its intended to do like what you told in this post..
In your code that you have done,you only evaluate the variable "a" with the other variables that you have declared,which is of course it is wrong..and then in the end of your code,you wrote
which is simply print all those variables,thus your if/else statement before were all useless...
What you should actually do is cin>> all the five numbers entered by user into 5 variables like a,b,c,d,e...
Then you may use the operator to compare those 5 variables...
The first step you should do is by sorting them manually in a piece of paper before you do your program...The sorting will be like this :
a b c d e
a b c e d
a c b d e
a c b e d
a d b c e
a d b e c
a e b c d
a e b d c
b a c d e
b a c e d
b c a d e
b c a e d
b d a c e
b d a e c
b e a c d
b e a d c
c a b d e
c a b e d
c b a d e
c b a e d
c d a b e
c d a e b
c e a b d
c e a d b
d a b c e
d a b e c
d b a c e
d b a e c
d c a b e
d c a e b
d e a b c
d e a c b
e a b c d
e a b d c
e b a b c
e b a c b
e c a b d
e c a d b
e d a b c
e d a c b
After sorting them like this..I advice that you write the code for cout<<
first,an then only you compare them using the operator...
The coding is just the same like what i've shown you in the previous reply..
eg.
I hope you could understand these all...But if you still got problem,be free to ask
Its look like you still not getting the idea...
Sorry for saying this,but your code its completely wrong if its intended to do like what you told in this post..
In your code that you have done,you only evaluate the variable "a" with the other variables that you have declared,which is of course it is wrong..and then in the end of your code,you wrote
C++ Syntax (Toggle Plain Text)
cout << "Your Number Are: " << v << " " << w << " " << x << " " << y << " " << z;
What you should actually do is cin>> all the five numbers entered by user into 5 variables like a,b,c,d,e...
Then you may use the operator to compare those 5 variables...
The first step you should do is by sorting them manually in a piece of paper before you do your program...The sorting will be like this :
a b c d e
a b c e d
a c b d e
a c b e d
a d b c e
a d b e c
a e b c d
a e b d c
b a c d e
b a c e d
b c a d e
b c a e d
b d a c e
b d a e c
b e a c d
b e a d c
c a b d e
c a b e d
c b a d e
c b a e d
c d a b e
c d a e b
c e a b d
c e a d b
d a b c e
d a b e c
d b a c e
d b a e c
d c a b e
d c a e b
d e a b c
d e a c b
e a b c d
e a b d c
e b a b c
e b a c b
e c a b d
e c a d b
e d a b c
e d a c b
After sorting them like this..I advice that you write the code for cout<<
first,an then only you compare them using the operator...
The coding is just the same like what i've shown you in the previous reply..
eg.
C++ Syntax (Toggle Plain Text)
if(a<b<c<d<e) { cout<<a<<b<<c<<d<<e; .......... }
I hope you could understand these all...But if you still got problem,be free to ask
![]() |
Similar Threads
- ascending order (C++)
- C++ with Emacs ascending order! Please help me out (C++)
- put linked lists in ascending order (C++)
- Printing numbers in ascending order (help) (C++)
- Random number with ascending order help (C++)
Other Threads in the C++ Forum
- Previous Thread: NIM Game
- Next Thread: not sure why i am outputting all zeros
Views: 2492 | Replies: 25
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment beginner binary c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error exception file files filestream forms fstream function functions game givemetehcodez graph graphics gui helpwithhomework homework iamthwee input int lazy link linked-list linker list loop looping loops math matrix member memory newbie number object objects opengl output parameter path pointer pointers problem program programming project python random read reading recursion recursive reference search sort spoonfeeding string strings struct student studio template templates text time tree url variable vc++ vector video visual win32 window windows winsock wxwidgets






