Printing Array In Reverse Order

 

# include  <iostream>
using namespace std ;
int main(){
int length_of_array ;

cout << "Enter the no. of Elements :" ;
cin >> length_of_array ;

int array[length_of_array];

for (int i = 0; i < length_of_array; ++i) {
cin >> array[i] ;
}

cout << "Elements from Left to Right : " << '\n' ;
for (int i = 0; i < length_of_array; i++) {
cout << array[i] << " " ;

}
cout << '\n' ;

cout << "Elements from Right to Left : " << '\n';
for (int i = length_of_array - 1; i >=0 ; i--) {
cout << array[i] << " " ;

}
return 0 ;
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2