Print array in reverse order || Arrays || C++

In this, we are going to print the elements of array in reverse order in  C++.

The code given below can be used for TURBO C++ Compiler:-

// printing array in reverse order
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int b[5],i,j;

    // Taking array elements as input
    cout<<"Enter array elements\n";
    for(i=0;i<5;i++)
    {
        cin>>b[i];
    }

    // printing array elements
    cout<<"Th array elements are :"<<endl;
    for(j = 0;j<5;j++)
    {
        cout<<b[j]<<"\n";
    }

    // printing array elements in reverse order
    cout<<"The array in reverse order is :"<<endl;
    for(j = i-1;j>=0;j--)
    {
        cout<<b[j]<<"\n";
    }
    getch();
}
  
  

The code given below can be used for g++/gcc Compiler:-

// printing array in reverse order
#include<iostream>
using namespace std;
int main()
{
    int b[5],i,j;

    // Taking array elements as input
    cout<<"Enter array elements\n";
    for(i=0;i<5;i++)
    {
        cin>>b[i];
    }

    // printing array elements
    cout<<"Th array elements are :"<<endl;
    for(j = 0;j<5;j++)
    {
        cout<<b[j]<<"\n";
    }

    // printing array elements in reverse order
    cout<<"The array in reverse order is :"<<endl;
    for(j = i-1;j>=0;j--)
    {
        cout<<b[j]<<"\n";
    }
    return 0;
}

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post