How to Use If-Else & Loops in C? | Prime Number Program

How to Use If-Else & Loops in C? | Prime Number Program

📌 Learn how to use if-else statements and loops together in C programming with a Prime Number Checker! In this tutorial, we’ll write a Prime Number Checker in C, using if-else statements and loops. This is a step-by-step beginner-friendly guide to understanding decision-making and iteration in C programming. ✅ What You’ll Learn: 🔹 How if-else and for loops work together in C 🔹 When to use if, else, and loops for efficient programming 🔹 A real-world example: Prime Number Checker 💡 Topics Covered: ✅ What is a prime number? ✅ How to check if a number is prime using loops and if-else ✅ Optimizing the loop using sqrt(n) for efficiency 👨‍💻 Code Used in This Video: #define _CRT_SECURE_NO_WARNINGS #include stdio.h #include math.h void main() { int num; int isPrime = 1; printf("Enter the number "); scanf("%d", &num); if (num greater= 1 && num less= 3) { isPrime = 1; } else { for (int i = 2; i less= sqrt(num); i++) { if (num % i == 0) { isPrime = 0; break; // } } } if (isPrime == 1) { printf("%d is a Prime Number", num); } else { printf("%d is not a Prime Number", num); } } 🔔 Subscribe for More C Programming Tutorials! 📢 Watch Next: 💬 Have questions? Drop a comment below, and I’ll be happy to help! 🚀