As mentioned in the comments, array should be initialized with a proper capacity. You should first read the size and then create the array.
#include <iostream>
using namespace std;
int main() {
int n;
// First read the array size and then create the array.
cin>>n; //inputting the array size
int array[n];
//inputting the numbers
// Remember indices go from 0 to N-1
for(int c=0;c<n;c++)
{
cin>>array[c];
}
//outputing the numbers reversed
for(int x=n-1;x>=0;x--)
{
cout<<array[x]<<" ";
}
return 0;
}
1
solved in the c++ hacker rank preperation cause, the last index returns 0 when i reverse it. but when i try the code out in visual studio, it works perfectly [closed]