## Prime or Not – C Program

### Write a c program for check the inputted number is prime or not.

The prime number is divisible only by itself, and the rest of all numbers are composite.

Here is the c program for check the given number is prime or not using for loop.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include<stdio.h> #include<conio.h> void main() { int n, a = 2; printf("Enter the number for check prime or not : \n"); scanf("%d",&n); for (a = 2 ; a <= n - 1 ; a++) { if (n%a == 0) { printf("The number %d is not prime.\n", n); break; } } if (a == n) { printf("The number %d is prime.\n", n); } } |

The out put of check prime number c program is :

1 2 3 4 5 6 7 8 9 |
Enter the number for check prime or not : 100 The number 100 is not prime. ////////// Enter the number for check prime or not : 11 The number 11 is prime. |

(Visited 6 times, 1 visits today)