Prime Number Program in C

Prime Number Program in C


C Program to Find Prime Number

Any natural number not divisible by other numbers except one and itself is called Prime Number in C. Let us see how to write a C Program to Find Prime Number using For Loop, While Loop, and Functions.

Prime Numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, etc. 2 is the only even prime number in C

C Program to Find Prime Number Using For Loop

This program allows the user to enter any integer value. Using this value, this C program will check whether the given number is a Prime number or Not using For Loop.

#include <stdio.h>
 
int main()
{
  int i, Number, count = 0; 
   
  printf("\n Please Enter any number to Check for Prime \n");
  scanf("%d", &Number);
 
  for (i = 2; i <= Number/2; i++)
   {
     if(Number%i == 0)
     {