Reverse a number
Ninja is feeling very bored and wants to try something new. So, he decides to find the reverse of a given number. But he cannot do it on his own and needs your help.
Note:
If a number has trailing zeros, then its reverse will not include them. For e.g., the reverse of 10400 will be 401 instead of 00401.
Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains one integer ‘N’ denoting the given number.
Output Format:
For each case, you need to print the reverse of the given number.
The output of each test case will be printed on a separate line.
Note:
You do not need to input or print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N <= 10 ^ 18
Time Limit = 1 sec
CodingNinjas
author
2y
Algorithm :
Input: num
(1) Initialize rev_num = 0
(2) Loop while num > 0
(a) Multiply rev_num by 10 and add remainder of num
divide by 10 to rev_num
rev_num = rev_num*10 + num%10;
(b) Divide num by 10
(3) R...read more
CodingNinjas
author
2y
Number Manipulations
Firstly to solve the problem of trailing zeros, we can run a while loop that shall divide the number by 10 and the condition for the while loop shall be that the modules of the num...read more
Help your peers!
Add answer anonymously...
Top UnitedHealth Business Analyst interview questions & answers
Popular interview questions of Business Analyst
Top HR questions asked in UnitedHealth Business Analyst
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app