Sunday, 29 June 2014

C++ program to extract digits of a number using recursion


Here is a C++ program to extract digits of a number using recursion


 SOURCE CODE OUTPUT
#include<iostream>
#include<math.h>
using namespace std;
void digit(int n)
{
    if(n==0)
        return ;
    digit(n/10);
    cout<<n%10<<",";
}
int main()
{
    int n,pow,result;
    cout<<"Enter the number : ";
    cin>>n;
    cout<<"Digits of number : ";
    digit(n);
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment