Monday, 14 March 2016

Hacker Rank Solution Program In C++ For "Arrays Introduction "

#include <iostream>
#include <cstdio>
using namespace std;

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

    for(int i = n - 1; i >= 0; i--){
        cin >> array[i];
        cout << array[i] << " ";
    }
    return 0;
}


Output:-

Hacker Rank Solution Program In C++ For "Arrays Introduction "

4 comments:
Write comments
  1. for(int i = n - 1; i >= 0; i--){
    // cin >> array[i];
    cout << array[i] << " ";

    I have marked the unnecesarry line. u dont need to read values again cause there isnt a second value entrance.

    ReplyDelete
  2. nt n;
    cin >> n;
    int array[n];

    Hi Execute this piece of code in VS 2013 or any version. Look for the error. Its wrong. Kindly correct it.

    ReplyDelete
    Replies
    1. if you are facing error then change your code:=
      int arr[100],n;
      cin>>n;
      some compiler doesnt support that time of declaration and initilization i advice change you compilor

      Delete

Recommended Posts × +