Program to print all even digit from a number using recursion in C++.
Solution
#include <iostream> using namespace std; void calculate(int n){ if(n == 0) return; calculate(n / 10); if((n%10)%2==0) cout << n % 10 << endl; } int main() { int n,ans; cout<<"Enter a number :- "; cin>>n; calculate(n); return 0; }
Output :
Enter a number :- 1453 4