We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I though Variable Length Arrays (VLAs) where not supported by C++, and my compiler thinks so too. I had to use vectors,
#include<cmath>#include<vector>#include<iostream>usingnamespacestd;intmain(){intn{};cin>>n;if(n<1||n>1000)return1;vector<int>vec(n);// Read array.for(inti=1;i<n+1;i++){// Load input back to front so its reversed.cin>>vec[n-i];// Validate.if(vec[n-i]<1||vec[n-i]>10000)return1;}// Output array.for(inti=0;i<n;i++){cout<<vec[i]<<" ";}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays Introduction
You are viewing a single comment's thread. Return to all comments →
I though Variable Length Arrays (VLAs) where not supported by C++, and my compiler thinks so too. I had to use vectors,