Patrick and Johnny started to play card game-II. In this game, one player has to pick all the cards which are shuffled on the table and another player has to type the card number in the system within 30 minutes. So Patrick decided to pick cards and Johnny decided to type card number in the system. Johnny had a strange habit of reading the numbers from reverse and he had entered all the numbers in reverse. He had made around 10000 entries when his friend Patrick found the mistake. He knows that it is impossible for him to correct all the 10000 entries in a 30 minutes time manually. They approach you and ask for your help.
Can you please help them?
Write a C program to reverse a given number using for loop.

Input Format:
Input consists of a single integer, which corresponds to 'n'.

Output Format:
The output consists of a single integer, which corresponds to the reverse of 'n'. The leading 0's are omitted.

[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output 1:
Enter the card number typed by Johnny:
32
The reverse order of 32 is 23.
 
Sample Input and Output 2:
Enter the card number typed by Johnny:
450
The reverse order of 450 is 54.


Program Code:
#include<stdio.h>
int main()
{
    int i,n,r,s=0;
    printf("Enter the card number typed by Johnny:\n");
    scanf("%d",&n);
    for(i=n;i>0; )
    {
        r=i%10;
        s=s*10+r;
        i=i/10;
    }
    printf("The reverse order of %d is %d.",n,s);
    return 0;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: