Back to Browse

Prime Number | Do/While Loop | Lecture #81 #numbersystem #armstrong #coding #logical #developer

19 views
Mar 1, 2026
15:10

πŸ”Ž Purpose of This Program This program checks whether a given number is a prime number using a do-while loop. 🧩 Variable Explanation num β†’ Stores the number entered by the user. rem β†’ Declared but not used in the program. temp = 1 β†’ Used as a flag variable. 1 means the number is assumed to be prime. 0 means the number is not prime. c = 2 β†’ Used to check divisibility starting from 2. πŸ–₯ Step-by-Step Working 1️⃣ User Input The program asks the user to enter a number. That number is stored in the variable num. 2️⃣ Do-While Loop Starts The loop checks whether the number is divisible by values starting from 2 up to num/2. Why up to num/2? Because a number cannot have a factor greater than half of itself (except the number itself). 3️⃣ Inside the Loop It checks: πŸ‘‰ If the number is divisible by c If yes: It means the number has another factor. So it is not prime. temp becomes 0. The loop stops using break. If not: It increases c by 1. The loop continues. 4️⃣ Loop Condition The loop continues while: c is less than or equal to num/2 5️⃣ Final Check After the loop ends: If temp is still 1 β†’ No number divided it β†’ It is Prime If temp is 0 β†’ It was divisible β†’ It is Not Prime ⚠ Important Observation (Small Mistake in Logic) If the user enters: 0 or 1 The program will incorrectly say it is Prime, because the loop will not run properly. But actually: 0 is NOT prime 1 is NOT prime So a condition should be added to handle numbers less than or equal to 1. 🎯 Summary βœ” The program uses a do-while loop βœ” It checks divisibility from 2 to num/2 βœ” Uses a flag variable to decide prime or not βœ” Works correctly for numbers greater than 1 βœ” Small improvement needed for 0 and 1 #coding #hindi #maths #numbers #logical #cprogramming #developer #study #concept #iteration #controlstatements

Download

1 formats

Video Formats

360pmp414.0 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Prime Number | Do/While Loop | Lecture #81 #numbersystem #armstrong #coding #logical #developer | NatokHD