problem no 6: Reverse the number.

 QUESTION:

Given N,  reverse the digits of N.
 

Example 1:

Input: 200
Output: 2
Explanation: By reversing the digts of number, 
number will change into 2.

Example 2:

Input : 122
Output: 221
Explanation: By reversing the digits of number,
number will change into 221. 
 
 

ANSWER:

long long int reverse_digit(long long int n)
        {
          long long int result=0;
          while(n>0)
          {
              int rem=n%10;
             
              result=result*10+rem;
              n=n/10;
          }
          return result;
        }

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.