Wednesday, 19 May 2021

Cpp-slip28a

 

Write a C++ program to read array of ' n' integers from user and display it in reverse order.(Use Dynamic memory allocation)

 #include<iostream.h>

#include<string.h>

#include<conio.h>

#include<stdio.h>

int main() {

int x, n;

cout << "Enter the number of items:" << "\n";

cin >>n;

int *arr = new int(n);

cout << "Enter " << n << " items" << endl;

for (x = 0; x < n; x++) {

cin >> arr[x];

}

cout << "You entered: ";

for (x = 0; x < n; x++) {

cout << arr[x] << " ";

}

 for(x=n-1;x>=0;x--)

{

cout << arr[x]<<"";

}

 return 0;

}