How to find reverse of a given number in c programming:-
This program reverses a number entered by a user and then prints it. For example, if a user will enter 6577756 as input then 6577756 will be printed as output.
This C program accepts an integer and reverses it.
This C program accepts an integer and reverses it.
Step 1. Take the number which you have to reverse as the input variable says the number.
Step 2. Obtain its quotient and remainder.
Step 3. Multiply the separate variable with 10 and add the obtained remainder to it.
Step 4. Do step 2 again for the quotient and step 3 for the remainder obtained in step 4.
Step 5. Repeat the process until the quotient becomes zero.
Step 6. When it becomes zero, print the output and exit.
Step 7. Stop.
CODE: -
#include<stdio.h>
int main()
{
int num,rev=0,rem;
printf("Enter any number: ");
scanf("%d",&num);
while(num>0)
{
rem= num%10;
rev= rev*10+rem;
num=num/10;
}
printf("The reverse num is %d",rev);
return 0;
}
Comments
Post a Comment