hey everyone,
I'm trying to understand a calculation here why a certain function has to be the way it is.
Below is a code where the user enters a number for n times and then reverses it and on the for loop initializing the i, i don't understand why i have to divide the number by 2. Please have a look and explain it to me because i really don't understand
Code:
#include <stdio.h>
int main()
{
int arr[10];
int num,i, temp = 0;
printf("Enter Number: ");
scanf("%d", &num);
for (i=0; i<num; i++)
{
printf("Arr[%d]: ", i);
scanf("%d", &arr[i]);
}
for (i=0; i<num/2; i++) // Here i don't understand num/2
{
temp = arr[i];
arr[i] = arr[num-1-i];
arr[num-1-i] = temp;
}
for (i=0; i<num; i++)
{
printf("Arr[%d] = %d\n",i,arr[i]);
}
}