• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 10, 2022 |20.1K Views
C Program to Check Whether a Number is Prime or not
  Share  4 Likes
Description
Discussion

In this video, we will see C Program to Check Whether a given number is Prime or not. We know that “A prime number is a number that can only be divided by itself and 1 without remainders”. There are some examples of prime numbers from 1 to 100. [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]

Here we use Sqrt of N .The reason is that the smallest and greater than one factor of a number cannot be more than the sqrt of N. And we stop as soon as we find a factor.

Some interesting facts about prime numbers:

1. Two is the only even Prime number.
2. Every prime number can be represented in form of 6n+1 or 6n-1 except the prime number 2 and 3, where n is a natural number.
3. Two and Three are only two consecutive natural numbers that are prime.

Algorithm to print a prime numbers:
Step 1: First, take the numbers from user.
Step 2: Then use a IF-ELSE condition to check a number is a prime or not.
Step 3: If it is a prime number, print it.

Time Complexity: O(n1/2)
Auxiliary Space: O(1)

Program to Check whether a number is prime or not: https://www.geeksforgeeks.org/c-program-to-check-whether-a-number-is-prime-or-not/

Read More