Question:
Little man computer Input 5 numbers and output them in reverse order?
2014-02-27 09:21:16 UTC
I'm finding it extremely difficult to program this
"program that will input 5 numbers and then output them in reverse order?"
Help, thankyou need this today.
Five answers:
?
2014-02-27 10:20:14 UTC
Try this:

(You have to use a C++11 compiler)

#include

#include

#include

using namespace std;



int main()

{

array iNumber;

for (int i = 0; i < 5; i++) {

cout << i + 1 << "> ";

cin >> iNumber[i];

}

copy(iNumber.rbegin(), iNumber.rend(), ostream_iterator(cout, " "));

return 0;

}



Here above code slightly modified:

Capturing the data starts at the last array element ...

#include

#include

#include

using namespace std;



int main()

{

array iNumber;

for (int i = 4; i >= 0; i--) {

cout << 5 - i << "> ";

cin >> iNumber[i];

}

copy(iNumber.begin(), iNumber.end(), ostream_iterator(cout, " "));

cout << endl;

// or alternately you could use another for loop like this:

for (int i = 0; i < 5; i++)

cout << iNumber[i] << " ";

cout << endl;

return 0;

}
smith
2017-01-19 05:25:09 UTC
1
2015-08-19 11:51:49 UTC
This Site Might Help You.



RE:

Little man computer Input 5 numbers and output them in reverse order?

I'm finding it extremely difficult to program this

"program that will input 5 numbers and then output them in reverse order?"

Help, thankyou need this today.
Robert G
2014-02-27 09:26:15 UTC
Use an array to store the numbers with a for loop. Increment the loop from 1 to 5 for input. Use another for loop with a decrementing counter to display.
Veo
2014-02-27 09:31:49 UTC
#include

#include

#include



int main(int argc, char *argv[]) {



long int i0 = argc>1 ? strtol(argv[1],NULL,10) : 0;

long int i1 = argc>2 ? strtol(argv[2],NULL,10) : 0;

long int i2 = argc>3 ? strtol(argv[3],NULL,10) : 0;

long int i3 = argc>4 ? strtol(argv[4],NULL,10) : 0;

long int i4 = argc>5 ? strtol(argv[5],NULL,10) : 0;

printf("%lu %lu %lu %lu %lu\n", i4, i3, i2, i1, i0);

return 0;

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...