1. Write a program that asks the user the size and the elements of the array. The program should display the reverse of the array.

Example:

INPUT output
Enter the List The list
10 10 20 30 40 50
20
30 The inverse of the list
40 50 40 30 20 10
50

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Lucaci Andrew

The example you posted doesn't make any sense to me. If you input 5 numbers 1 2 3 4 5 the inverse is 5 4 3 2 1, is that what you want?

OP! Here you go......

To make it easy and simple.
1st you must declare an array of ints, having known its size, like:

int array [5];

2nd you must introduce items into the array, by parshing through it and assigning each element to corresponding position in the array. Say, you have an array of 5 items, you have also those 5 items: 12,43,15,652,231, all you have to do is to asign items to the array.

array[0]=12;

3rd get the reverse of the list by printing the list in reverse order, as this:

//by knowing its size of 5:
for (int i=5;i--;){
}

for (int i=5;i--;){

I know what you mean, but it would be better to make a standard loop that newbe can understand and that us oldies don't have to think very much about (our thinking power is somewhat diminished)

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

Edited by Ancient Dragon

Yes :) you could make it more visible that way...
Kinda ironic this example, since I've tried to make it an easy example. Indeed, that makes the looping more visible.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.