ToMotion AI logo
Menu
Back to gallery

Public AI explainer video

C Prime Number Check: Control Flow in OnlineGDB

When n % i == 0 is true, n has a factor besides 1 and itself. Set isPrime to 0. Then break stops the loop. There is no reason to keep dividing after...

Prompt

Source idea used to generate this video.

Use following content & Explain it in hindi but in romanhindi, dont use hindi hard words, use English words for English Terms. Explain in Tutor Style, Also dont write Hindi words while explaining, only English letters can be used. Control Flow Structures with Write programs in c for prime number checks explain the code step by step in online GDB

Narration

Narration used to create this video.

Video narration

When n % i == 0 is true, n has a factor besides 1 and itself. Set isPrime to 0. Then break stops the loop. There is no reason to keep dividing after you already know the number is non-prime. Finally, print the result after the loop: if (isPrime == 1) { printf("%d is prime", n); } else { printf("%d is not prime", n); } Now dry run it with 17. The status starts at 1. Since 17 is greater than 1, the loop begins. For i equal to 2, 17 % 2 is not 0. For i equal to 3, it is not 0. For i equal to 4, the loop condition fails because 4 times 4 is greater than 17. No divisor was found, so 17 is prime. Try 18 next. At i equal to 2, 18 % 2 is 0. The status becomes 0, break stops the loop, and the program prints that 18 is not prime. So the answer is simple: no random guesses. If division finds a divisor, the number is non-prime; if none appears, it is prime.