Answer to Question #297000 in C++ for Harsh

Question #297000

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-12T14:39:02-0500


#include <iostream>
#include <math.h>


using namespace std;


bool isPrime(int num)
{
	if (num < 2)
	{
		return false;
	}
	if (num == 2 || num == 3)
	{
		return true;
	}
	for (int i = 2; i <= sqrt(num * 1.0); i++)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
	return true;
}


int main(){




	long int regNumber;


	cout<<"Input your registration number(8-digits) in the University: ";
	cin>>regNumber;


	cout<<"\nThe prime numbers digits in your registration number: \n";
	while (regNumber > 0) {
		int d = regNumber % 10;
		if(isPrime(d)){
			cout<<d<<"\n";
		}
		regNumber = regNumber / 10;
	}






	cin>>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