**Prime number program in C **is one of the most important programs in c.

### What is a prime number?

Any number which is divisible only by one and itself. two (2) is the smallest even prime number. for example prime numbers are: **2, 3, 5, 7, 11, 13, 17,…..**

A number greater than one can be factorized into prime numbers, for example, **540 = 2 ^{2}*3^{3}*5^{1}**.

## C Program to Check Whether a Number is Prime or not

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> main() { int n, c = 2; printf("Enter a number to check if it is prime\n"); scanf("%d",&n); for ( c = 2 ; c <= n - 1 ; c++ ) { if ( n%c == 0 ) { printf("%d isn't prime.\n", n); break; } } if ( c == n ) printf("%d is prime.\n", n); return 0; } |

**Output :**

__Related Post__

- Print 1 to 100 numbers.
- Print alphabets from A-Z
- Find odd and even number
- Print all odd numbers till N
- Swap numbers using third variable
- Swap numbers without using third variable
- Find given number leap year or not
- Convert given days to years,week and day
- Multiply two numbers without using multiplication operator
- Calculate gross salary from given basic pay
- Reverse the given number

## Leave a Reply