In: Computer Science
/*Use recursion in the function: void getDigit( int num)
/* Try this program and implement the function void getDigit( intnum) so that it displays the digits in a given number. For example, the number, 1234 consist of 1, 2, 3 and 4.
This is an exercise to demonstate the use of a recursive function and the use of recusrion in C++
*/
#include
#include
using namespace std;
int main()
{
int num;
cout <<"Enter an integer: ";
cin >> num;
//getDigit(num);
cout<<"\n\n";
int digit;
while (num >0){
digit = num
% 10;
cout
<< digit<
num /=
10;
}
system ("pause");
return 0;
}
If you have any doubts, please give me comment...
/*Use recursion in the function: void getDigit( int num)
/* Try this program and implement the function void getDigit( intnum) so that it displays the digits in a given number. For example, the number, 1234 consist of 1, 2, 3 and 4.
This is an exercise to demonstate the use of a recursive function and the use of recusrion in C++
*/
#include <iostream>
// #include<>
using namespace std;
void getDigit(int num);
int main()
{
int num;
cout << "Enter an integer: ";
cin >> num;
getDigit(num);
// system ("pause");
return 0;
}
void getDigit(int num){
if(num>0){
getDigit(num/10);
cout<<num%10<<endl;
}
}