Check if Number is Prime
📖 Scenario: You are helping a friend who wants to know if a number is prime. A prime number is a number greater than 1 that has no divisors other than 1 and itself.We will write a simple program in C to check if a given number is prime.
🎯 Goal: Build a C program that checks if a number is prime by testing divisibility from 2 up to the number minus one.
📋 What You'll Learn
Create an integer variable called
number with the value 29Create an integer variable called
is_prime and set it to 1 (true)Use a
for loop with variable i from 2 to number - 1Inside the loop, check if
number is divisible by iIf divisible, set
is_prime to 0 (false) and break the loopPrint
"Prime" if is_prime is 1, otherwise print "Not Prime"💡 Why This Matters
🌍 Real World
Prime numbers are used in cryptography, computer security, and coding theory.
💼 Career
Understanding prime checking helps in algorithm design and problem solving in software development.
Progress0 / 4 steps
