C Program to Print Prime Numbers from 1 to N.
source link: https://www.geeksforgeeks.org/videos/c-program-to-print-prime-numbers-from-1-to-n/
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.
C Program to Print Prime Numbers from 1 to N.
- 10 Views
- 11/08/2022
In this video, we will write a C Program to print all the prime numbers from 1 to N.
What is a prime number?
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 are as follows:
[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]
Algorithm to print prime numbers from 1 to N:
Step 1: First, take the input N number from the user.
Step 2: Then use an iterative method to iterate the numbers from 1 to N and check each number to be a prime number.
Step 3: Print the all is a prime number up to N.
Examples:
Input number: N = 10
Output prime numbers: 2, 3, 5, 7
Input number : N = 5
Output prime numbers: 2, 3, 5
Here time and space complexity for this method is O(n^2/3) & O(1).
C Program to print prime numbers from 1 to N: https://www.geeksforgeeks.org/c-program-to-print-prime-numbers-from-1-to-n/
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK