5

C Program to Check Whether a Number is Prime or not

 2 years ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-check-whether-a-number-is-prime-or-not/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

C Program to Check Whether a Number is Prime or not

C Program to Check Whether a Number is Prime or not
Hello friends. Welcome to weeks for Geeks. So
  • 10/06/2022

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/


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK