Q: if a five digit number is input through the keyboard write a program to reverse the number.


# include <stdio.h>
int main()
{
    int n,rem,rev;
   
    printf("enter any number : ");
    scanf("%d",&n);
   
    while(n!=0)              /*condition used until n becomes zero*/
   
    {
        rem= n%10;           /*to find the last digit of no*/
        n=n/10;                   /*as n is int so n/10 also be int*/
        rev=rev*10+rem;    /*to find the reverse of the no entered*/
    }
   
    printf("reverse of no is %d",rev);
   
    return 0;
}
-----------------------------------------
output:

enter any number : 12345
reverse of no is 54321

Comments

Popular posts from this blog

Q: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate area & perimeter of the rectangle and area & circumference of the circle.

Q: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)