Keywords: prime c program, c program for prime numbers, c program to find prime numbers, a program for the prime number in c, c program for a prime number. In this example, you will learn how to check whether the input number is a Prime number or not. See the below example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<stdio.h> int main() { int num, i, count = 0; printf("Enter a number:"); scanf("%d", &num); for (i = 2; i <= num / 2; i++) { if (num % i == 0) { count++; break; } } if (count == 0) printf("%d is a prime number", num); else printf("%d is not a prime number", num); return 0; } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program for prime number, c program for prime numbers, c program to find prime numbers, c tutorials, prime number program in c, write a program to find prime numbers from 1 100