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;scanf("%d",&num);arr=(int*)malloc(num*sizeof(int));for(i=0;i<num;i++){scanf("%d",arr+i);}intcount=0;// i for loop which takes last value of an array and assign it to temp variable // j for loop which moves whole array but doesn't affect variables which has been or will be assigned // temp value is assigned the [count] position of array for(inti=num-1;i>=0;i--){inttemp=arr[num-1];for(intj=num-1;j>count;j--){*(arr+j)=*(arr+j-1);}arr[count]=temp;count++;}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 →