9. Design a class named "Prime" having the following data members and member functions: Data Members: int n : stores the number which is to be checked whether it is a prime number or not. Member Functions: void accept() : accepts the value of 'n' from the user using Scanner class object. void check() : displays "Prime Number" if 'n' is a Prime Number otherwise displays "Not a Prime Number int countDigits(): returns the number of digits of 'n' and also display the sum of the square of the digits of the number 'n'. You must also write the main() to show the calling or invoking of the functions of the above class. (Non-anonymous question o)
Answers
Answered by
2
The simplest primality test is trial division: given an input number, n, check whether it is evenly divisible by any prime number between 2 and √n (i.e. that the division leaves no remainder). If so, then n is composite. Otherwise, it is prime.
I hope it will be help you.
Similar questions
English,
8 days ago
Geography,
8 days ago
Math,
17 days ago
Biology,
9 months ago
Computer Science,
9 months ago