C program to reverse numbers and print them on the screen. For example, if the input is 12345, we will print the output like 54321. In the program, we use the modulus operator (%) to obtain the digits of the number. To invert the number write its digits from right to left (reverse).
C program to find the reverse of user-given numbers
//By - blog.mrwixxsid.com
#include <stdio.h>
int main()
{
int n, r = 0;
printf("Enter numbers to reverse\n");
scanf("%d", &n);
while (n != 0)
{
r = r * 10;
r = r + n%10;
n = n/10;
}
printf("Reverse of the number = %d\n", r);
return 0;
}
0 Comments