Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- void f(int x, int& primality);
- int main(void) {
- using namespace std;
- int x, primality = 0;
- cout << "Введите число: ";
- cin >> x;
- f(x, primality);
- if(primality == 1)
- cout << "Число простое" << endl;
- else
- cout << "Число составное" << endl;
- return 0;
- }
- void f(int x, int& primality) {
- primality = 1;
- for(int i = 2; (i <= sqrt(x)) && (primality == 1); ++i) {
- if(x % i == 0)
- primality = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement