Advertisement
Guest User

Vitaly Pavlenko / Prime or composite?

a guest
Feb 12th, 2011
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     int i;
  9.     for (i = 2; i <= n; ++i) {
  10.         bool isPrime = true;
  11.         int j;
  12.         for (j = 2; j < i; ++j)
  13.             if (i % j == 0)
  14.                 isPrime = false;
  15.         if (isPrime)
  16.             cout << i << " is prime" << endl;
  17.         else
  18.             cout << i << " is composite" << endl;
  19.     }
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement