Skip to main content
Skip to content

Math · Beginner

Prime Number Program in Hindi Coding

Function with boolean return value, break statement, and logic.

The program

Edit anything and press Run. The output below was produced by running this exact code.

Expected output

Press Run to try it

29 ek prathamik (Prime) sankhya hai!

How it works

A prime number has exactly two divisors: 1 and itself. The function rules out everything below 2 first, then tries every divisor i starting at 2.

The loop only runs while i * i <= num. If a number has a divisor bigger than its square root, it must also have one smaller than it, so checking further would be wasted work. That one condition makes the check much faster for large numbers.

As soon as a divisor is found, lautao galat exits the function. If the loop finishes without finding one, the function reaches lautao sahi.