YAMILDIAZ

ejemplo 3

Jun 14th, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. //Declaracion  de funcion
  6. bool primo(int num);
  7.  
  8. int main(){
  9. int num;
  10.  
  11. cout<<"ingrese un numero: ";
  12. cin>>num;
  13.  
  14. if(primo(num)){
  15.     cout<<"verdadero";
  16. }else{
  17.     cout<<"falso";
  18. }
  19.  
  20.  
  21. cout<<endl;
  22. system("pause");
  23. return 0;
  24. }
  25. //Defenicion de la funcion
  26. bool primo(int num){
  27. int i, contprimo=0;
  28. for (i = 1; i <= num; i++){
  29.     if (num%i==0){
  30.         contprimo++;
  31.     }
  32. }
  33.  
  34. if (contprimo == 2){
  35.     return true;
  36. }else{
  37.     return false;
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment