Answer to Question #297213 in C for Aman

Question #297213

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


1
Expert's answer
2022-02-13T09:42:31-0500


#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",&registrationNumber);
	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",&registrationNumber);
	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