Advertisement
Abelsor

Verificar Primo

Feb 18th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. string primo(int a);
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cout<<"Ingrese un numero: ";
  9.     cin>>n;
  10.     cout<<primo(n);
  11. }
  12.  
  13. string primo(int a)
  14. {
  15.     int cont = 0;
  16.     for(int i=0 ; i<a ; i++){
  17.         if(a%(i+1)==0)
  18.             cont++;
  19.     }
  20.    
  21.     if(cont == 2)
  22.         return "Es Primo";
  23.     else
  24.         return "No es Primo";
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement