Commit 17ed4b9
committed
feat: Identify and print prime numbers from 2 to 20 using nested loops
🔍 Logic:
- Outer loop increments through numbers 2 to 20.
- Inner loop checks divisibility from 2 to current number.
- If `divisor == currentNumber`, it means no smaller divisor was found → prime.
- If divisible earlier, print "NOT a prime" and exit inner loop early.
🛠️ Note:
`break` should be used after detecting a non-prime to skip unnecessary checks.
Signed-off-by: Somesh diwan <[email protected]>1 parent 32af786 commit 17ed4b9
File tree
1 file changed
+24
-0
lines changed- Section7ConditionalStatements/Loops/src
1 file changed
+24
-0
lines changedLines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments