A program to check if the number is prime or composite using function in C++

#include<iostream>
#include<conio.h>
void check(int);
using namespace std;
int main()
{
int n;
cout<<“enter a number”;
cin>>n;
check(n);
getch();
}
void check(int n)
{
int s=0,i;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
s++;
}
}
if(s==2)
{
cout<<“Prime”;
}
else
{
cout<<“Composite”;
}
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *