- 3

I need ascending and descending order c++ program without array. Because i'm new student in CS ?

without array.. in simple way.. and user give input also three input number option

11th Mar 2018, 4:27 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
31 Answers
+ 9
@Farhan: Effectively Kinshuk was your google on this one :) but IF you google the methods he has provided and figure out how and why they work for yourself I see no harm in being provided with code like this. Personally I wouldn't have answered this question until I had seen what you have tried yourself first, but that's just me (sounds a bit like homework, that's why) :)
11th Mar 2018, 8:25 AM
jay
jay - avatar
11th Mar 2018, 8:44 AM
jay
jay - avatar
+ 11
If you post the code here or save it as a code in code playground :) I will be able to see
11th Mar 2018, 9:10 AM
jay
jay - avatar
+ 10
Wooooo nice! Can I see?
11th Mar 2018, 9:07 AM
jay
jay - avatar
+ 9
p.s It doesn't matter if your attempt is wrong :) as long as it shows you tried, people will be very, very happy to help Also, Kinshuk is more deserving of best answer than me
11th Mar 2018, 8:37 AM
jay
jay - avatar
+ 6
The logic is very much the same with @Kinshuk solution, I see you try to swap values using your own implementation rather than the algorithm library support, it's nice to see you try and play with it, it helps in learning, it's good for you : ) I would suggest you though, to create your own swap function and call it as necessary, rather than repetitively writing like these: swap = x x = y y = swap Good job! : )
11th Mar 2018, 9:39 AM
Ipang
+ 4
I don't know if it's helpful to give him the full code. He maybe just copies it and doesn't learn anything. This code is a bit more advanced than a hello world program and a cs student should be able to figure it out without getting a whole solution. Hints & corrections should be enough. Learning by doing and learning by errors are far better than learning by copy&paste. At least for beginners. For advanced techniques it's often helpful to look at decent open source codes though.
11th Mar 2018, 8:15 AM
Alex
Alex - avatar
+ 4
#include<iostream> using namespace std; int main() { int a,b,c,swap; cout<<"Enter Any Three Numbers ::>"<<endl; cin>>a>>b>>c; if(a>=b && a>=c) { swap=a; a=c; c=swap; } if(b>=a && b>=c) { swap=b; b=c; c=swap; } if(b<a) { swap=b; b=a; a=swap; } cout<<"\n\n\n In Ascending Order::> "; cout<<a<<" "<<b<<" "<<c; if(a<=b && a<=c) { swap=a; a=c; c=swap; } if(b<=a && b<=c) { swap=b; b=c; c=swap; } if(b>=a) { swap=b; b=a; a=swap; } cout<<"\n\n\n In Descending Order::> "; cout<<a<<" "<<b<<" "<<c; }
11th Mar 2018, 9:15 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
+ 3
plz elaborate the question.
11th Mar 2018, 4:46 AM
shobhit
shobhit - avatar
+ 3
What did you already try?
11th Mar 2018, 8:09 AM
Alex
Alex - avatar
+ 3
#include<iostream> using namespace std; int main() { int a,b,c,swap; cout<<"Enter Any Three Numbers ::>"<<endl; cin>>a>>b>>c; if(a>=b && a>=c) { swap=a; a=c; c=swap; } if(b>=a && b>=c) { swap=b; b=c; c=swap; } if(b<a) { swap=b; b=a; a=swap; } cout<<"\n\n\n In Ascending Order::> "; cout<<a<<" "<<b<<" "<<c; if(a<=b && a<=c) { swap=a; a=c; c=swap; } if(b<=a && b<=c) { swap=b; b=c; c=swap; } if(b>=a) { swap=b; b=a; a=swap; } cout<<"\n\n\n In Descending Order::> "; cout<<a<<" "<<b<<" "<<c; }
11th Mar 2018, 9:15 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
+ 3
Good job!
11th Mar 2018, 9:23 AM
Alex
Alex - avatar
+ 3
Thanks
11th Mar 2018, 9:27 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
+ 3
Thanks
11th Mar 2018, 9:52 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
+ 2
how would you sort something in ascending or descending without using array or something like array like vector. One way could be to find max & min. if ot doesn't solve your problem plz clarifyn
11th Mar 2018, 4:42 AM
shobhit
shobhit - avatar
+ 2
What do you want to sort? That will clear things...
11th Mar 2018, 4:53 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
I meant, what is the data that you need to sort? And how are you storing it without an array?
11th Mar 2018, 5:13 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
yeah sure
11th Mar 2018, 8:26 AM
Farhan Masood Khan
Farhan Masood Khan - avatar
+ 1
That's why I asked if you tried anything yourself yet.
11th Mar 2018, 8:18 AM
Alex
Alex - avatar
+ 1
Yahoo i have done it by if if if statement
11th Mar 2018, 9:06 AM
Farhan Masood Khan
Farhan Masood Khan - avatar