Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int x;
- cout << "Podaj liczbe naturalna: ";
- cin >> x;
- if(x < 2)
- cout << x << " nie jest liczba pierwsza.\n";
- bool pierwsza = true;
- for(int i = 2; i * i <= x; ++i)
- {
- if(x % i == 0)
- {
- pierwsza = false;
- break; // natychmiastowe wyjście z pętli
- }
- }
- if(pierwsza)
- cout << x << " jest liczba pierwsza.\n";
- else
- cout << x << " nie jest liczba pierwsza.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement