We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<stdio.h>#include<stdlib.h>intmain(){intnum,*arr,i,temp;scanf("%d",&num);arr=(int*)malloc(num*sizeof(int));for(i=0;i<num;i++){scanf("%d",&arr[i]);}/* Write the logic to reverse the array. *//*Two-pointer approach: pointer left which starts from left - initialize it to zero pointer right which starts from right - initialize it to last element of the array*/intleft=0;intright=num-1;/*swapping of numbers*/while(left<right){temp=arr[left];arr[left]=arr[right];arr[right]=temp;left++;right--;}for(i=0;i<num;i++)printf("%d ",arr[i]);return0;free(arr);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Reversal
You are viewing a single comment's thread. Return to all comments →