Arrays introduction C++ HackerRank solution

A series of elements can be used in a lot of conditions where it can come in handy to solve problems by iterating through a series of variables. This tutorial will help you with Arrays introduction C++ HackerRank solution.

arrays introduction c++ hackerrank solution

Problem statement

An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier…

You can check out the complete problem on Arrays introduction at HackerRank.

Also Read: Hackerrank problem on for loop

Solution

It first takes a variable named ‘n’ which holds the length of the array, later it runs ‘for loop’ respectively to take input of the array and to print the array by iterating through the loop.

#include <iostream>
using namespace std;


int main() {
    
    int n;
    cin >> n;
    int arr[n];

    for(int i=0; i<n; i++){
        cin >> arr[i];
    }

    for(int j=n; j>0; j--){
        cout << arr[j-1] <<" ";
    }
    return 0;
}
Sharing Is Caring:
Soumya Mondal

An aspiring BTech Electronics and Communication student, obsessed with Coding, Gadgets, Blogging, & Digital Marketing.

Leave a Comment