Reverse an Array

QUESTION

Given an array, print reverse of it.\n\nInput:\n\nFirst line contains an integer, the number of test cases ‘T’ Each test case should contain an integer, size of array ‘N’ in the first line. In the second line Input the integer elements of the array in a single line separated by space.\n\nOutput:\n\nPrint the array in reverse order in a single line separated by space.Each array is to be printed in separate line.\n\nConstraints:\n\n1 <= T <= 100\n\n1 <= N <=100\n\n0 <= Arr[i] <= 100.

“TESTCASE_1”: “1\n4\n1 2 3 4\n###—###SEPERATOR—###—\n4 3 2 1”, “TESTCASE_2”: “1\n5\n2 4 6 8 10\n###—###SEPERATOR—###—\n10 8 6 4 2 “, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
void rvereseArray(int arr[], int start, int end)
{
    int temp;
    while (start < end)
    {
        temp = arr[start];   
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }   
}     
 
/* Utility that prints out an array on a line */
void printArray(int arr[], int size)
{
  int i;
  for (i=0; i < size; i++)
    printf("%d ", arr[i]);
 
  printf("\n");
} 

int main()
  
{
  int x;
  scanf("%d", &x);
  int i=0;
  for(i=0;i<x;i++)
  {
    int y;
    scanf("%d", &y);
    int j;
    int arr[y];
    for(j=0;j<y;j++)
    {
      scanf("%d", &arr[j]);
    }
        rvereseArray(arr, 0, y-1);
    printArray(arr, y);    
  }
 
  //  rvereseArray(arr, 0, 5);
  //  printArray(arr, 6);    

	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro