Sunday, 6 December 2015

Arrays -DS

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'll be given an array of N integers, and you have to print the integers in reverse order.
Note: If you have already solved the problem "Arrays Introduction" in the Introduction chapter of the C++ domain, you may skip this challenge.
Input Format
The first line of input contains N, 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 on a single line separated by single spaces.
Sample Input
4
1 4 3 2
Sample Output
2 3 4 1
Copyright © 2015 HackerRank.
All Rights Reserved

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int n, in[1000], i;
    scanf("%d",&n);
    for( i = 0 ; i < n ; i++ )
        {
        scanf("%d",&in[i]);
    }
    for( i = n - 1 ; i >= 0 ; i-- )
        {
        printf("%d\t",in[i]);
    }    
    return 0;
}

No comments:

Post a Comment