Advertisement
alias3glw

NumeroPrimo

May 27th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     int N,i,div=2;
  9.    
  10.     cout<<"Ingrese un valor"<<endl;
  11.     cin>>N;
  12.    
  13.     if ( N%2==0 && N!=2 ){
  14.        
  15.         cout<<"No es numero primo"<<endl;
  16.     } else {
  17.        
  18.        
  19.         for ( i=3 ; i<N ; i++ ){
  20.            
  21.             if ( N%i==0 ){
  22.                
  23.                 div=div+1;
  24.             }
  25.         }
  26.        
  27.         if ( div>2 ) {
  28.        
  29.         cout<<"No es numero primo"<<endl;
  30.         } else {
  31.            
  32.             cout<<N<<" ";
  33.     }  
  34.    
  35.     system("PAUSE");
  36.     return EXIT_SUCCESS;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement