This is a basic program in Cpp which checks whether the number is prime number or composite number.
A number is said to be prime if it is divided by 1 and itself other numbers are called composite however the numbers 0 and 1 are neither prime or composite.
PROGRAM :
#include <iostream>
using namespace std;
int main()
{
int i,n;
cout << "Enter any number : \t" << endl;
cin >> n ;
if(n == 0 || n == 1)
cout << n << " is neither PRIME nor COMPOSITE" << endl;
for ( i = 2 ; i <= n-1 ; i++ )
{
if ( n%i == 0 )
{
cout << n << " is COMPOSITE number" << endl;
break;
}
}
if ( n == i )
cout << n << " is PRIME number" << endl;
return 0;
}
OUTPUT :
|
Cpp - Prime Or Composite |
|
Cpp - Prime Or Composite |
|
Cpp - Prime Or Composite |
No comments:
Post a Comment