Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- int main(){
- unsigned long x;
- int i=2;
- bool isPrime=true;
- cout<<"Questo programma verifica se l'input è un numero primo o meno"<<endl;
- cin>>x;
- if(x==0 || x==1)
- cout<<"Input invalido: digitare un numero >= 2"<<endl;
- if(x==2 || x==3)
- cout<<x<<" è numero primo"<<endl;
- if(x>3){
- while(i<x && isPrime){
- if (x%i==0){
- cout<<x<<" non è numero primo"<<endl;
- isPrime=false;
- }
- ++i;
- }
- }
- if (x>3 && isPrime==true)
- cout<<x<<" è numero primo"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement