Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5.  
  6. int main(){
  7. unsigned long x;
  8. int i=2;
  9. bool isPrime=true;
  10. cout<<"Questo programma verifica se l'input è un numero primo o meno"<<endl;
  11. cin>>x;
  12. if(x==0 || x==1)
  13. cout<<"Input invalido: digitare un numero >= 2"<<endl;
  14. if(x==2 || x==3)
  15. cout<<x<<" è numero primo"<<endl;
  16. if(x>3){
  17. while(i<x && isPrime){
  18. if (x%i==0){
  19. cout<<x<<" non è numero primo"<<endl;
  20. isPrime=false;
  21. }
  22. ++i;
  23. }
  24. }
  25. if (x>3 && isPrime==true)
  26. cout<<x<<" è numero primo"<<endl;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement