Computer Science, asked by krishiganesh, 1 year ago

WRITE A FUNCTION PROGRAM IN C++ TO FIND THE REVERSE OF ANY NUMBER.

Answers

Answered by Tina11111
0
#include <iostream>

#include <math.h>

 

using namespace std;

 

//Fuction declaration

int reverseNumber(int num);

 

int main()

{

int num, reverse;

 

// Inputting number from user

cout<<"Enter any number: ";

cin>>num;

 

// Calling function to reverse any number

reverse = reverseNumber(num);

 

cout<<"Reverse of number "<<num <<" is: "<<reverse;

 

return 0;

}

 

//Recursive function to find reverse of any number

 

int reverseNumber(int num)

{

// Find total digits in num

int digit = (int) log10(num);

 

// Base condition

if(num == 0)

return 0;

 

return ((num%10 * pow(10, digit)) + reverseNumber(num/10));

}


krishiganesh: hello sista it is showing as error
Tina11111: error
krishiganesh: yes
Tina11111: public class ReverseNumber { public static void main(String[] args) { int num = 1234, reversed = 0; while(num != 0) { int digit = num % 10; reversed = reversed * 10 + digit; num /= 10; } System.out.println("Reversed Number: " + reversed); } }
krishiganesh: I am doing it in turbo
Similar questions