Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool es_primo(int& numero) {
  5.   int d=2;
  6.     while (d*d<=numero) {
  7.       if (numero%d==0) return false;
  8.       else ++d;
  9.     }
  10.     return true;
  11. }
  12.  
  13. int main () {
  14.   int n;
  15.   cin >> n;
  16.   for (int i=1; i<=n; ++i) {
  17.     int numero;
  18.     cin >> numero;
  19.     if (es_primo(numero)) cout << numero << " es primer" << endl;
  20.     else cout << numero << " no es primer" << endl;
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement