Arrays hackerrank solution in c++

C++
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int n,i=0;
    cin>>n;
    int *a = new int[n];
    while(cin>>a[i++]);
    while(cout<<a[--n]<<' '&& n);
    delete[] a; 
    return 0;
}

Source

Also in C++: