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: Two number are input through the keyboard into two two locations C and D. write a program to interchange the contents of C and D.

Q: Consider a currency system in which there are note of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. if a sum of Rs. N is entered through the keyboard, write a program to compute the smallest number of notes that will combine to give Rs N.