Array Reversal
#include <stdio.h> #include <stdlib.h> int main() { int num, *arr, i; scanf("%d", &num); arr = (int*) malloc(num * sizeof(int)); for(i = 0; i < num; i++) { scanf("%d", arr + i); } for(i = num-1; i>-1; i--) printf("%d ", *(arr + i)); return 0; }
Am I leaning in the right direction with my code? I'm currently working on hacker rank and am on the easy section of data structures yet I still am confused about how to reverse this array! Out of all my attempts, I like these two that I did. Check it out. one attempt: two attempts:
Show hidden low quality content
|