(1494 Views)

A prime number is a number which is divisible by only two numbers: 1 and itself. So, if any number is divisible by any other number, it is not a prime number.

When you run the program, the output will be:

In the above program, checkPrime function takes 'no' as parameter to check whether it is prime or not. In the loop x value changes from 2 to (no/2). In every iteration, we check if the number is divisible by x, if yes directly come out of the loop and obviously value of x will be less than (no/2), else continue with the iteration until the last element i.e (no/2). After that we just check if the value of x is greater than (no/2), if yes return true else return false.

In showMessage Function, we pass the Value to be checked using Result(13) and store the boolean result in 'answer' variable. Then based on the value returned by checkPrime function, we just print either "Is Prime" or "Not Prime"

3 UpvotesUpvote |
0 DownvotesDownvote |

- Algorithm and Flowchart for Area of Triangle [606 Views]
- Download AngularJS Up & Running by Shyam Seshadri & Brad Green PDF [2512 Views]
- Find HCF and LCM using Python [1844 Views]
- How to send a Header data through HTTP Request using curl [768 Views]
- Algorithm and Flowchart to Find transpose of a matrix [2588 Views]

- How To Win Ludo King Game Every Time [28722 Views]
- Algorithm to find whether number is Armstrong Number or Not [26456 Views]
- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [24386 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [19456 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [14422 Views]