Day 7: array|| hackerrank || 30 days of code || programming_info

Objective
Today, we're learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given an array, , of  integers, print 's elements in reverse order as a single line of space-separated numbers.
Input Format
The first line contains an integer,  (the size of our array).
The second line contains  space-separated integers describing array 's elements.
Constraints
  • , where  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
Solution using C language:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
     int n,a[1000],i,j,t;
      cin>>n;
      for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
     for(j=0;j<n;j++);
        for(i=0;i<(j/2);i++)
                {
                    t=a[i];
                    a[i]=a[n-i-1];
                    a[n-i-1]=t;
                }
    for(i=0;i<n;i++)
        {
            cout<<a[i]<<" ";
        }
    return 0;
}
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support