Answers for "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 ."

C++
0

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 <bits/stdc++.h>
using namespace std;
//use c++ 17
int main(){
    int n;
    cin>>n;
    for(int i =n-1;;i--){
    	if(i%2!=0 && i%3!=0 && i%5!=0){
    		cout<<i;
    		break;
		}
	}
	return 0;
}
Posted by: Guest on February-06-2022

Code answers related to "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 ."

Browse Popular Code Answers by Language