// recursive function to print digit of number in revers order
void rev_dig(int num)
{
if(num==0)
return;
else
{
cout<<num%10<<" ";
// recursive call
rev_dig(num/10);
}
}
// driver function
int main()
{
int num;
cout<<"enter a number:";
// read the number from user
cin>>num;
cout<<"digits in revers order: ";
// call the function with number parameter
rev_dig(num);
return 0;
}
Explanation:
Read the input from user and assign it to variable "num". Call the function "rev_dig" with "num" parameter.In this function it will find the last digit as num%10 and print it. Then call the function itself with "num/10". This will print the second last digit. Similarly it will print all the digits in revers order.