Advertisement
dimonstrer

Untitled

Dec 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <locale.h>
  4. using namespace std;
  5.  
  6. int check(int a);
  7.  
  8. int main()
  9. {
  10.     setlocale(LC_ALL, "Russian");
  11.     int a = 1;
  12.     int k = 0;
  13.     cout << "Введите число: " << endl;
  14.     while (a)
  15.     {
  16.         cin >> a;
  17.         if (!a)
  18.             break;
  19.         k+=check(a);
  20.     }
  21.     cout << "Кол-во простых чисел: " << k << endl;
  22.     _getch();
  23. }
  24.  
  25. int check(int a)
  26. {
  27.     if (a == 2)
  28.         return 0;
  29.     for (int i = 2; i < a; ++i)
  30.         if (a%i == 0)
  31.             return 0;
  32.     return 1;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement