- 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
31 Antworten
+ 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) :)
+ 11
;) this may help in future questions too:
https://www.sololearn.com/Blog/38/8-simple-rules-to-get-help-from-the-community
+ 11
If you post the code here or save it as a code in code playground :) I will be able to see
+ 10
Wooooo nice! Can I see?
+ 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
+ 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! : )
+ 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.
+ 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;
}
+ 3
plz elaborate the question.
+ 3
What did you already try?
+ 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;
}
+ 3
Good job!
+ 3
Thanks
+ 3
Thanks
+ 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
+ 2
What do you want to sort? That will clear things...
+ 2
I meant, what is the data that you need to sort? And how are you storing it without an array?
+ 2
yeah sure
+ 1
That's why I asked if you tried anything yourself yet.
+ 1
Yahoo i have done it
by if if if statement