We will write a C program to display the reverse of the given number and the number will be entered by the user. This will help to understand the basic structure of programming. In this program , we will display the reverse of given numbers easily by using proper syntax and algorithms.
Working of Program :
In the program, we will require some numbers from the user to display the reverse of the given numbers.
#include<stdio.h>
int main ()
{
int n = 4567, reverse = 0, rem;
while (n != 0)
{
rem = n % 10;
reverse = reverse * 10 + rem;
n /= 10;
}
printf ("Reversed number = %d", reverse);
return 0;
}
#include<stdio.h>
int main ()
{
int n = 8967, a, r, s = 0;
a = n;
do
{
r = n % 10;
s = s * 10 + r;
n = n / 10;
}
while (n > 0);
printf ("\nThe Reverse Number = %d",s);
return 0;
}
Output
The Reverse Number = 7698
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment