Show Array Values in Reverse Order C++ (.cpp)

Show Array Values in Reverse Order C++ (.cpp)

“How to Show Array Values in Reverse Order C++ (.cpp)” is the today topic of discussion in this tutorial.

What is reverse order?

Suppose, the user enters the numbers as follows;

Entered numbers: 4, 2, 9, 1

In this case, the reverse order will be looks like;

Reverse Numbers: 9, 4, 2, 1

Now, Let’s see the program.

Show Array Values in Reverse Order in C++  using Arrays

In this example, we have created the two arrays;

int array1[100];

int reverse[100];

Let’s see the “Show Array Values in Reverse Order in C++  using Arrays”.

Output

How to Show Array Values in Reverse Order C++ (.cpp)
Figure: How to Show Array Values in Reverse Order C++ (.cpp)

Show Array Values in Reverse Order in C++  using for loop

Let’s see the “Show Array Values in Reverse Order in C++  using for loop”.

Show Array Values in Reverse Order in C++  using While loop

Let’s see the “Show Array Values in Reverse Order in C++  using While loop”.

Show Array Values in Reverse Order in C++  using User Define Functions

In this example, we have created the user defines a function. The user define function is declared, defined and call as mentioned below;

Function Declaration: int fun(int, int[], int[]);

Function Definition:

int fun(int size, int array1[100], int ReverseNumbers[100])
{

for(int i=size-1, num=0; i>=0; i–, num++)
{
ReverseNumbers[i]=array1[num];
}

}
Function Calling: fun(size,array1,ReverseNumbers);

Let’s see the “Show Array Values in Reverse Order in C++  using user define functions”.

 

Topic Covered

How to Show Array Values in Reverse Order C++ (.cpp).

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]