1#include <iostream>
2using namespace std;
3
4int main()
5{
6 int n, i;
7 bool isPrime = true;
8
9 cout << "Enter a positive integer: ";
10 cin >> n;
11
12 for(i = 2; i <= n / 2; ++i)
13 {
14 if(n % i == 0)
15 {
16 isPrime = false;
17 break;
18 }
19 }
20 if (isPrime)
21 cout << "This is a prime number";
22 else
23 cout << "This is not a prime number";
24
25 return 0;
26}
1#include<bits/stdc++.h>
2using namespace std;
3bool Is_Prime(long long x){
4 if(x%2==0)return false;
5 for(int i=3;i*i<=x;i+=2)
6 if(x%i==0)return false;
7 return true;
8}
9int main(){
10 long long x;
11 cin>>x;
12 if(Is_Prime(x))cout<<"Is Prime";
13 else cout<<"Is not Prime";
14}
1template<class T> bool isPrime(T n)
2{
3 T i;
4 if(i<2) return false;
5 for(i = 2; i * i <= n; i++) {
6 if(n % i == 0) return false;
7 }
8 return true;
9}