The program must enter a natural number n from the console and find the number previous to n that is not divisible by 2 , 3 and 5 .
#include <iostream>
bool isDivisible(int n) {
return (n % 2 == 0) || (n % 3 == 0) || (n % 5 == 0);
}
int findPreviousNonDivisible(int n) {
while (isDivisible(n)) {
n--;
}
return n;
}
int main() {
int number;
std::cout << "Enter a natural number: ";
std::cin >> number;
int result = findPreviousNonDivisible(number);
std::cout << "The number previous to " << number << " that is not divisible by 2, 3, or 5 is: " << result << std::endl;
return 0;
}