All prime numbers

Given an integer N, print all the prime numbers that lie in the range 2 to N (both inclusive).

Input Format :
Integer N
Output Format :
Prime numbers in different lines
Constraints :
1 <= N <= 100
CodingNinjas
author
2y

You can solve this problem using brute force or sieve of eratosthenes. I solved it using sieve of eratosthenes

CodingNinjas
author
2y
Space Complexity: Explanation: Time Complexity: Explanation:
Gaurav Sharma
1y

step 1: Take a Boolean vector initialize all the position with true

step 2: Now iterate the outer loop from i=2 to sqrt of n

step 3: when u got arr[i]=true means this is a prime number so all the multip...read more

Add answer anonymously...
Indiamart Intermesh Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter