C Program to reverse number:
We can reverse a number in c using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number. Let’s see a simple c example to reverse a given number.
#include<stdio.h>
int main()
{
int n, reverse=0, rem;
printf(“Enter a number: “);
scanf(“%d”, &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf(“Reversed Number: %d”,reverse);
return 0;
}
Output:
Enter a number: 123 Reversed Number: 321
Related Post:
Features of C Programming Language
Dynamic memory allocation in C
Difference Between Type Casting and Type Conversion in C
Difference Between Variables and Constants
C Program to generate Fibonacci Triangle
C Program to print “hello” without semicolon
C Program to swap two numbers without third variable
ount the number of digits in C