Advertisement
Guest User

7.3

a guest
Nov 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. void f(int x, int& primality);
  5.  
  6. int main(void) {
  7.     using namespace std;
  8.     int x, primality = 0;
  9.    
  10.     cout << "Введите число: ";
  11.     cin >> x;
  12.     f(x, primality);
  13.    
  14.     if(primality == 1)
  15.         cout << "Число простое" << endl;
  16.     else
  17.         cout << "Число составное" << endl;
  18.  
  19.     return 0;
  20. }
  21.  
  22. void f(int x, int& primality) {
  23.     primality = 1;
  24.     for(int i = 2; (i <= sqrt(x)) && (primality == 1); ++i) {
  25.         if(x % i == 0)
  26.             primality = 0;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement