HackerRank Solutions – 30 Days of Code – Day 7

HackerRank Solutions – 30 Days of Code – Day 7

 

Objective
Today, we’re learning about the Array data structure.

Task
Given an array, A, of  integers N print ‘s elements  A in reverse order as a single line of space-separated numbers.

Input Format

The first line contains an integer N,  (the size of our array).
The second line contains N  space-separated integers describing  A array ‘s elements.

Constraints

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

Output Format

Print the elements of array  in reverse order as a single line of space-separated numbers.

Sample Input

4
1 4 3 2

Sample Output

2 3 4 1

PROGRAM:

#include<stdio.h>
#include<stdlib.h>
int main()
{
    long int a[1000],b[1000],temp,n;
    int i,j;
    scanf("%li",&n);
    for(i=0;i<n;i++)
        scanf("%li",&a[i]);
    for(i=0,j=n-1;j>=0;i++,j--)
        b[j]=a[i];
    for(i=0;i<n;i++)
        printf("%li ",b[i]);
}


OUTPUT:

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Input (stdin)
4
1 4 3 2
Your Output (stdout)
2 3 4 1 
Expected Output
2 3 4 1
Follow us on Social Media:

Be the first to comment

Leave a Reply

Your email address will not be published.