
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Check if a number is Full Prime in C++
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
#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
- Related Articles
- How To Check If The Number Is A Prime Number In Excel?
- Check if a number is Quartan Prime or not in C++
- Check if a number is Primorial Prime or not in Python
- Check if a number is Primorial Prime or not in C++
- Check if a number is a Pythagorean Prime or not in C++
- C# Program to check if a number is prime or not
- Python program to check if a number is Prime or not
- PHP program to check if a number is prime or not
- Check if a number is divisible by all prime divisors of another number in C++
- Bash program to check if the Number is a Prime or not
- Write a C# program to check if a number is prime or not
- Check if N is a Factorial Prime in Python
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- Check if N is Strong Prime in Python
- How to check whether a number is a prime number or not?

Advertisements