prime number c++
template<class T> bool isPrime(T n)
{
T i;
if(i<2) return false;
for(i = 2; i * i <= n; i++) {
if(n % i == 0) return false;
}
return true;
}
prime number c++
template<class T> bool isPrime(T n)
{
T i;
if(i<2) return false;
for(i = 2; i * i <= n; i++) {
if(n % i == 0) return false;
}
return true;
}
c++ program to find prime number using function
#include<iostream>
using namespace std;
bool isPrimrNumber(int number){
bool isPrimeFlag=true;
for(int i=2;i<number;i++){
if(number%i==0){
isPrimeFlag=false;
break;
}
}
return isPrimeFlag;
}
int main()
{
int number;
cout<<"Please enter your number";
cin>>number;
bool isPrimeFlag=isPrimeNumber(number)
if(isPrimeFlag)
{
cout<<"prime Number";
}
else
{
cout<<"not prime number";
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us