Prime Number Program in C++
Prime Number program in C++ using for loop.
- #include<iostream>
- using namespace std;
- int main()
- {
- int n, i, m=0, count=0;
- cout << "Enter the Number to check Prime: ";
- cin >> n;
- m=n/2;
- for(i = 2; i <= m; i++)
- {
- if(n % i == 0)
- {
- cout<<"Number is not Prime."<<endl;
- count=1;
- break;
- }
- }
- if (count==0)
- cout << "Number is Prime."<<endl;
- return 0;
- }
-
Output:
Enter any number to check prime or not: 13
Number is Prime.
0 Comments
you can ask question related to this post