In C++ Using recursion write a program that takes a positive integer number and returns whether there is 6. For example, if the input number is 7068, the function returns true
#include <iostream> using namespace std; bool has_6(int n) { if (n == 0) { return false; } else if (n % 10 == 6) { return true; } else { return has_6(n / 10); } } int main() { int n; cout << "Enter a positive integer: "; cin >> n; cout << boolalpha << has_6(n) << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.