Answer to Question #293942 in C++ for Varun Dogra

Question #293942

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-04T14:49:48-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 registrationNumber;


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


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






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