An array is type of data structure that stores the elements in contiguous block of memory, create an array with name "list" and size of an array is N. your task is to print the array elements in an reverse order.
list-[1,2,3,4,5)
output 5,4,3,2,1
Note: use function concept to process the array elements and print it in the reverse order.
Reverse array has the following parameter
int list[n]
return int
#include <iostream>
using namespace std;
#define N 5
main()
{
int list[N] = {1,2,3,4,5};
int r;
cout<<"\n\tArray in original form: ";
for(r=0;r<N;r++) cout<<list[r]<<", ";
cout<<"\n\n\tArray in REverse order: ";
for(r=N-1;r>=0;r--) cout<<list[r]<<", ";
}
Comments
Leave a comment