Answer to Question #297795 in C for Harsh

Question #297795

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

1
Expert's answer
2022-02-17T02:12:38-0500
#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",&regNumber);
	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",&regNumber);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS