Previous Next
0 / 33
Module DEMO-32-60DEMO-C-32

Prime Numbers in Range

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program that reads two integers A and B and prints all prime numbers between A and B (inclusive).

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Example

For input 10 20, the prime numbers in that range are 11 13 17 19.

Requirements

  • Use nested loops to solve this problem.
  • Check each number in the range [A, B] for primality.

Constraints

You must use nested loops in your solution.

Input Format

Two integers A and B on a single line, where 1 <= A <= B <= 1000.

Output Format

Print all prime numbers between A and B (inclusive), separated by spaces.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
1 10
2 3 5 7
Input: 1 10
Sample #2
Public sample
1 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
Input: 1 100
Sample #3
Public sample
1 5
2 3 5
Input: 1 5
Sample #4
Public sample
20 30
23 29
Input: 20 30

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings