C++/dev c++
Expert: vijayan - 4/9/2009
Questioni am a student trying to learn dev c++ and i am having trouble making a program. the program description is Write a C++ program that asks the user to enter 6 numbers separated with spaces
and then prints out the entered numbers in reverse order. A sample output is shown
below:
*******************************
REVERSE NUMBERS
*******************************
Enter 6 numbers: 2 5 7 1 8 9
The reverse is : 9 8 1 7 5 2
Your program should use 2 for loops, an array and a const int called ARRAYSIZE.
i am having trouble creating the for loop to reverse the numbers..
Answerfirst declare an array that can hold six numbers
enum { ARRAYSIZE = 6 } ;
int numbers[ARRAYSIZE] ;
then, write a loop that iterates through array indices starting at 0 and ending at ARRAYSIZE-1. in the loop, accept the number and store it in the array.
to print out the numbers in reverse, write a loop that iterates through array indices starting at ARRAYSIZE-1 and ending at 0. in the loop, print out the number at the particular index in the array.
for( int i = ARRAYSIZE-1 ; i >= 0 ; --i )
// TODO: print out the number at numbers[i] here
note: dev c++ is just an IDE (a development environment). the compiler you are using is some version of the GNU C++ compiler (g++). and what you are trying to learn is programming in the C++ programming language. so the code that you write is specific to C++ (you could use any conforming C++ compiler to compile it, and you may use any suitable IDE.)