| | |
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
0
#11 Nov 17th, 2009
is it something like this exist..??
C++ Syntax (Toggle Plain Text)
if ( a < b && a < c && a < d && a < e)
•
•
Join Date: Oct 2009
Posts: 82
Reputation:
Solved Threads: 1
0
#13 Nov 17th, 2009
It should be more or less like this :
Nope...u cannot compare or inserting the range when using the switch..
C++ Syntax (Toggle Plain Text)
if (a<b && b<c && c<d && d<e) cout<<a<<b<<c<<d<<e;
•
•
Join Date: Jan 2008
Posts: 3,885
Reputation:
Solved Threads: 511
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?
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?
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.
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!
0
#18 Nov 18th, 2009
In psuedocode of course :
C++ Syntax (Toggle Plain Text)
void insertionSort(int * Array, int size) { //declare minElem variable to 0 //for i = 0 to i < size, increment i by 1 { //set minElem to i //for j = i +1 to j < size; increment j by 1 { //if array[j] is less than array[minElem] //then set minElem to j } //now swap array at i with array at minElem } }
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!
•
•
Join Date: Jan 2008
Posts: 3,885
Reputation:
Solved Threads: 511
1
#19 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.. >.<
By the way, have you written it for sorting two, three, and four numbers? That comes before five. Get the pattern down.
•
•
Join Date: Jan 2008
Posts: 3,885
Reputation:
Solved Threads: 511
0
#20 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.. >.<
![]() |
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: 2139 | Replies: 25
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays assignment beginner binary borland c++ c/c++ calculator char class classes code compile compiler console constructor conversion convert count data delete desktop dll encryption error file forms fstream function functions game givemetehcodez graph homework http iamthwee ifstream input int java lazy lib link linker list loop looping loops map math matrix memory newbie news number objects output pointer pointers problem program programming project python qt read recursion recursive reference return search sort sorting spoonfeeding string strings struct student studio system template templates text tree url variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency wxwidgets






