C Program to check a number is prime or not


In this program, You will learn how to check a number is prime or not in c.


Some list of prime numbers is : 2, 3, 5, 7, 11


Example: How to check a number is prime or not in c

Run it Now
#include<stdio.h>

int main() {

   int n, i, p = 1;
   printf("Enter a Number :");
   scanf("%d", &n);

   for (i = 2; i < n; i++) {
       if (n % i == 0) {
           p = 0;
           break;
       }
   }

   if (p == 1) {
       printf("\nNumber is Prime :%d", n);
   } else {
       printf("\nNumber is Not Prime :%d", n);
   }

   return 0;
}

Output:

Enter a Number :7
Number is Prime :7