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