Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define wtrue "Numarul este prim."
- #define wfalse "Numarul nu este prim."
- using namespace std;
- int main()
- {
- int n, i;
- cin >> n;
- if(n <= 1) cout << wfalse;
- else if(n == 2) cout << wtrue;
- else if(n % 2 == 0) cout << wfalse;
- else
- {
- bool prim = true;
- for(i = 3; i * i <= n && prim == true; i += 2)
- if(n % i == 0) prim = false;
- if(prim == true) cout << wtrue;
- else cout << wfalse;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment