print out number in ascending order in c++ WITHOUT USING ARRAY AND FUNCTION

Please support our C++ advertiser: Download Intel® Parallel Studio Eval
Thread Solved

Join Date: Nov 2009
Posts: 10
Reputation: din_hilmi is an unknown quantity at this point 
Solved Threads: 0
din_hilmi din_hilmi is offline Offline
Newbie Poster
 
0
  #11
Nov 17th, 2009
is it something like this exist..??
  1. if ( a < b && a < c && a < d && a < e)
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: din_hilmi is an unknown quantity at this point 
Solved Threads: 0
din_hilmi din_hilmi is offline Offline
Newbie Poster
 
0
  #12
Nov 17th, 2009
is it possible to use 'switch' or 'for' statement in this problem..??
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 82
Reputation: samsons17 is an unknown quantity at this point 
Solved Threads: 1
samsons17 samsons17 is offline Offline
Junior Poster in Training
 
0
  #13
Nov 17th, 2009
It should be more or less like this :

  1. if (a<b && b<c && c<d && d<e)
  2. cout<<a<<b<<c<<d<<e;
Nope...u cannot compare or inserting the range when using the switch..
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,885
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 511
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
2
  #14
Nov 17th, 2009
Five numbers can be ordered 5! or 120 ways. The no-brainer way of writing this code would thus be writing an if statement with 119 "else if" statements, one for each possible ordering. You should be using <= instead of < (what if two elements are the same?). There may be some clever nested-if ways of doing this that don't require 120 if statements of some sort. I suppose that might be interesting to have a contest where you had to sort 5 numbers without using arrays or functions and people might come up with creative answers.

But the larger question is this: why are you adding these stipulations? There's a reason why all the sorting algorithms out there use arrays and/or helper functions/recursion. Why would anyone want to write 120 if-statements?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: din_hilmi is an unknown quantity at this point 
Solved Threads: 0
din_hilmi din_hilmi is offline Offline
Newbie Poster
 
0
  #15
Nov 18th, 2009
quite true vernon.. any idea to make it more simpler..?? im not allowed to use array and function to settle this assignment.. uhuh.. >.<
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,727
Reputation: firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light 
Solved Threads: 220
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Posting Virtuoso
 
0
  #16
Nov 18th, 2009
well since since there are 5! possible combination, the minimum
number of if stated you will use is 2^5 = 32.

That will suck.

Just use insertion sort, the idea behind it is to mid a max* element
and swap it with the last element. Then repeat it with the last element
decreasing by 1 each time.
The series 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Help me find the last ten digits of the series, 1^1 + 3^3 + 5^5 + 7^7 + 9^9 ... 997^997 + 999^999.
Oh come on, someone has to get it! 
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: din_hilmi is an unknown quantity at this point 
Solved Threads: 0
din_hilmi din_hilmi is offline Offline
Newbie Poster
 
-1
  #17
Nov 18th, 2009
I didnt get it 1stperson.. mind to show me..??
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,727
Reputation: firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light 
Solved Threads: 220
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Posting Virtuoso
 
0
  #18
Nov 18th, 2009
Originally Posted by din_hilmi View Post
I didnt get it 1stperson.. mind to show me..??
In psuedocode of course :

  1. void insertionSort(int * Array, int size)
  2. {
  3.  
  4. //declare minElem variable to 0
  5.  
  6. //for i = 0 to i < size, increment i by 1
  7. {
  8. //set minElem to i
  9. //for j = i +1 to j < size; increment j by 1
  10. {
  11. //if array[j] is less than array[minElem]
  12. //then set minElem to j
  13. }
  14. //now swap array at i with array at minElem
  15. }
  16. }
The series 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Help me find the last ten digits of the series, 1^1 + 3^3 + 5^5 + 7^7 + 9^9 ... 997^997 + 999^999.
Oh come on, someone has to get it! 
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,885
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 511
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
1
  #19
Nov 18th, 2009
Originally Posted by din_hilmi View Post
quite true vernon.. any idea to make it more simpler..?? im not allowed to use array and function to settle this assignment.. uhuh.. >.<
"Simple", "efficient", "correct", and "not tedious" are different concepts. Your "easiest", most brain-dead method is to make 120 "if" statements, not taking advantage of the results of previous tests. The CORRECT way is to use an array, function, or whatever is needed. Back to my original question. WHY are you limited with this restriction? What's your experience level? One can always avoid arrays by using pointer arithmetic in lieu of the [] operator, which is basically the same thing, so what's the point? Sounds like one of those classes where they require you to do it the WRONG way so you'll appreciate the RIGHT way when they get to teaching it. If that's the case, just write your 120 if-statements and get it over with, I guess.

By the way, have you written it for sorting two, three, and four numbers? That comes before five. Get the pattern down.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,885
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 511
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
0
  #20
Nov 18th, 2009
Originally Posted by din_hilmi View Post
quite true vernon.. any idea to make it more simpler..?? im not allowed to use array and function to settle this assignment.. uhuh.. >.<
Originally Posted by din_hilmi View Post
I didnt get it 1stperson.. mind to show me..??
I'm looking at the post times. This one comes two posts after firstPerson's post. Quite fast. I wouldn't "get it" either if I had to learn the Insertion Sort in two minutes. Since it uses an array, you can't use it anyway. No one's going to give you the code without some effort on your part.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2139 | Replies: 25
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC