Skip to main content

Featured

say hello world with C++ - Solution in Hacker Rank - hackerranksolutions8

  Objective This is a simple challenge to help you practice printing to  stdout . You may also want to complete  Solve Me First  in C++ before attempting this challenge. We’re starting out by printing the most famous computing phrase of all time! In the editor below, use either  printf  or  cout  to print the string  Hello ,World!  to  stdout . The more popular command form is  cout . It has the following basic form: cout<<value_to_print<<value_to_print; Any number of values can be printed using one command as shown. The  printf  command comes from C language. It accepts an optional format specification and a list of variables. Two examples for printing a string are: printf("%s", string);   printf(string); Note that neither method adds a newline. It only prints what you tell it to. Output Format Print   Hello ,World!   to stdout. Sample Output Hello, World! Solution:- //Say Hello, World! With C++ - Hacker Rank Solution #include <iostream> #include <cstdio

Arrays Introduction in C++ – Solution in Hacker Rank - hackerranksolutions8

 

Problem

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.
Declaration:

int arr[10]; //Declares an array named arr of size 10, i.e; you can store 10 integers.

Accessing elements of an array:

Indexing in arrays starts from 0.So the first element is stored at arr[0],the second element at arr[1]...arr[9]

You’ll be given an array of N integers and you have to print the integers in the reverse order.


Input Format

The first line of the input contains N,where N is the number of integers.The next line contains N integers separated by a space.

Constraints

  • 1<= N <= 1000
  • 1<= Ai <= 10000 where Ai is the ith integer in the array. 

Output Format

Print the N integers of the array in the reverse order in a single line separated by a space.


Sample Input

4
1 4 3 2

Sample Output

2 3 4 1

Solution :-   

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define MAX 10000
using namespace std;


int main() 
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int a[MAX], N,i;
    cin>>N;
    for(i=1;i<=N;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<N;i++)
    {
        cout<<a[N-i]<<" ";
    } 
    return 0;
}

Comments

Popular Posts