Prime Number Program in C++
Def : The number that is divided by 1 or itself and always greater than 1 . It can also be defined as the number which can are only divisional to 1. For example 2, 3, 5, 7, 11, 13, 17, 19, 23 are the prime numbers.
Here we will write a code which will detect whether the given number is prime or not.
- #include <iostream>
- using namespace std;
- int main()
- int a, i, b=0, flag=0;
- cout << “Please Enter a Number\n”;
- cin >> a;
- for(i = 2; i <= b; i++)
- if(a % i == 0)
- cout<<“Number is not Prime.”<<endl;
- if (flag==0)
- cout << “Number is Prime.”<<endl;
- return 0;