Take input of your registration number(19120856) in the University. Write a program to print all the prime numbers digits in your registration number.
#include <iostream>
using namespace std;
bool isPrime(int n) {
if ( n <= 1)
return false;
int i=2;
while (i*i <= n) {
if (n%i == 0)
return false;
i++;
}
return true;
}
int main() {
long number;
int d;
cout << "Enter a registration number ";
cin >> number;
cout << "The prime numbers in it are: ";
while (number > 0) {
d = number % 10;
number /= 10;
if (isPrime(d)) {
cout << d << " ";
}
}
}
Comments
Leave a comment