Take input of your registration number(8-digits) in the University. Write a program to print all the prime numbers digits in your registration number
#include<stdio.h>
#include<math.h>
int isPrime(int registrationNumber)
{
if (registrationNumber < 2)
{
return 0;
}
if (registrationNumber == 2 || registrationNumber == 3)
{
return 1;
}
for (int i = 2; i <= sqrt(registrationNumber * 1.0); i++)
{
if (registrationNumber % i == 0)
{
return 0;
}
}
return 1;
}
int main(){
int registrationNumber;
int d;
printf("Input your registration number(8-digits) in the University: ");
scanf("%d",®istrationNumber);
printf("\nThe prime numbers digits in your registration number: \n");
while (registrationNumber > 0) {
d = registrationNumber % 10;
if(isPrime(d)){
printf("%d\n",d);
}
registrationNumber = registrationNumber / 10;
}
scanf("%d",®istrationNumber);
return 0;
}
Comments
Leave a comment