A prime number is a number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number.

The number 2 (Two) is the only even and the smallest prime number. Prime numbers have many applications in computer science and mathematics such as cryptography and abstract algebra.

First few prime numbers less than 100 are:

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
Source: OEIS

Below is the C program to check if a number is prime.

C program to check for Prime Number

This C program prompts the user to enter an integer N. It prints out if it is a prime or not. If not, it prints out all of its proper factors.

Output of the program is:

And

C program to check for Prime Number using function

We can slightly modify the above program to check for prime number using function.

Output of the program is:

And

C program to print all prime numbers less than 100

We can further modify the above program to print all of the primer numbers in the range of 2-100.

Output of the program is: