Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. bool isPrime(int x);
  8.  
  9. int main()
  10. {
  11.     system("mode CON COLS=150 LINES=60");
  12.  
  13.     cout << "Liste des nombres premiers:" << endl;
  14.  
  15.     int colonne = 1;
  16.     int lines = 1;
  17.  
  18.     for (int i = 1200000; i <= 2147483647; i++)
  19.     {
  20.         if (isPrime(i))
  21.         {
  22.             cout << i << " ";
  23.             colonne++;
  24.  
  25.             if (colonne > 18)
  26.             {
  27.                 double percent = (i / 2147483647) * 100;
  28.  
  29.                 cout << "(" << percent << "%)" << endl;
  30.                 colonne = 1;
  31.                 lines++;
  32.  
  33.                 if (lines > 60)
  34.                 {
  35.                     lines = 1;
  36.                     system("cls");
  37.                 }
  38.             }
  39.         }
  40.  
  41.     }
  42.  
  43.     system("pause");
  44.  
  45.     return 0;
  46. }
  47.  
  48. bool isPrime(int x)
  49. {
  50.     bool _isPrime = true;
  51.  
  52.     if (x % 2 == 0)
  53.         _isPrime = (x == 2);
  54.  
  55.     for (int d = 3; d < x; d += 2)
  56.     {
  57.         if (x % d == 0)
  58.         {
  59.             _isPrime = false;
  60.             break;
  61.         }
  62.     }
  63.  
  64.     return _isPrime;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement