Given a number N, print all prime number smaller than or equal to N in reverse order .
For example, if N is 9, the output should be “7, 5, 3, 2”.
Input : N = 5 Output : 5 3 2 Input : N = 20 Output : 19 17 13 11 7 5 3 2
A simple solution is to traverse from N to 1. For every number, check if it is a prime using school method to check for prime. Print the number if it is prime.
An efficient solution is to use Sieve of Eratosthenes. We efficiently find all number from 1 to N, then print them.
Prime number in reverse order 23 19 17 13 11 7 5 3 2
- Print the nearest prime number formed by adding prime numbers to N
- Print prime numbers with prime sum of digits in an array
- Print characters having prime frequencies in order of occurrence
- Sort only non-prime numbers of an array in increasing order
- Sort prime numbers of an array in descending order
- Print prime numbers in a given range using C++ STL
- Program to print first N Prime numbers
- Print all prime numbers less than or equal to N
- Print all Semi-Prime Numbers less than or equal to N
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Python program to print all Prime numbers in an Interval
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.