Given a number, write a program to reverse the rightmost n digits, n is taken from the first digit of the given
number
Input Format
Input contains an integer value n
Output Format
Print the number after performing partial reverse
Constraints
1 <=N<=10410
Example
32145
First digit of a given number is 3. so the output is 32541
Answers
Answered by
0
Answer:
// C++ program to reverse digits of a number
#include <bits/stdc++.h>
using namespace std;
/* Recursive function to reverse digits of num*/
int reversDigits(int num)
{
static int rev_num = 0;
static int base_pos = 1;
if(num > 0)
{
reversDigits(num/10);
rev_num += (num%10)*base_pos;
base_pos *= 10;
}
return rev_num;
}
// Driver Code
int main()
{
int num = 4562;
cout << "Reverse of no. is "
<< reversDigits(num);
return 0;
}
Output:
Reverse of no. is 2654
Similar questions
Geography,
2 months ago
Accountancy,
2 months ago
Science,
2 months ago
Math,
4 months ago
CBSE BOARD X,
4 months ago
Math,
10 months ago
Hindi,
10 months ago