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,*arr2;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. */arr2=(int*)malloc(num*sizeof(int));i=0;for(intj=num-1;j>=0;j--){arr2[i]=arr[j];i++;}for(intx=0;x<num;x++){arr[x]=arr2[x];}free(arr2);for(i=0;i<num;i++){printf("%d ",arr[i]);}free(arr);return0;}
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 →