C Language "Check Number is prime or not using for loop" program with output

 #include <stdio.h>

int main() { int num, i, isPrime = 1; // Input a number from the user printf("Enter a positive integer: "); scanf("%d", &num); // Check for special cases if (num <= 1) { isPrime = 0; // 0 and 1 are not prime } else { for (i = 2; i <= num / 2; i++) { if (num % i == 0) { isPrime = 0; // If num is divisible by any number in this range, it's not prime break; } } } if (isPrime) { printf("%d is a prime number.\n", num); } else { printf("%d is not a prime number.\n", num); } return 0; }



Output:
Enter a positive integer: 17 17 is a prime number.

Comments

Popular posts from this blog

Video Formats

Where video editing is used

File saving and folder management