Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
 
PREVIOUS NEXT
Tagged: #The #program #enter #natural #number #console #find #number #previous #divisible
ADD COMMENT
Topic
Name
3+4 =