how to reverse an array in c code example
Example 1: reverse array in c
// arr is the array
// a is length of array
int j = a-1;
for(int i = 0; i<j; i++){
arr[i]^=arr[j];
arr[j]^=arr[i];
arr[i]^=arr[j];
j--;
}
Example 2: how to reverse a number in c
#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", rev);
return 0;
}