# Check if a number is Full Prime in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

Here we will see, how to check, whether a number is full prime or not. A number is said to be a full prime, if it is prime, and all of its digits are also prime. Suppose a number is 37, this is full prime. But 97 is not full prime as 9 is not a prime number.

One efficient approach is that; first we have to check whether any digit is present that is not prime. Digits must be in 0 to 9. In that range 2, 3, 5 and 7 are prime, others are not prime. If all are primes, then check whether the number is prime or not.

## Example

Live Demo

#include <iostream>
using namespace std;
bool isPrime(int n){
for(int i = 2; i<= n/2; i++){
if(n % i == 0){
return false;
}
}
return true;
}
bool isDigitPrime(int n) {
int temp = n, digit;
while(temp){
digit = temp % 10;
if(digit != 2 && digit != 3 && digit != 5 && digit != 7){
return false;
}
temp = temp / 10;
}
return true;
}
bool isFullPrime(int n){
return (isDigitPrime(n) && isPrime(n));
}
int main() {
int num = 37;
if(isFullPrime(num)){
cout << "The number is Full Prime";
} else {
cout << "The number is not Full Prime";
}
}

## Output

The number is Full Prime