Previous Next
0 / 15
Module DEMO-33-67DEMO-OOP-33

Prime Number Checker using for

DEMO-OOP-33 โ€ข Object Oriented Programming

Browser-only practice

Problem Statement

Write a C program that reads a positive integer from the user and determines whether it is a prime number.

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

Your program must use a loop to check for divisibility. Output one of the following messages based on the result:

  • PRIME if the number is prime.
  • NOT PRIME if the number is not prime.
  • INVALID INPUT if the number is less than or equal to 1.

Examples:

  • 2 is prime.
  • 4 is not prime (divisible by 2).
  • 1 is not prime (not greater than 1).

Input Format

A single line containing an integer n (1 <= n <= 10000).

Output Format

Print exactly one of the following strings:

  • PRIME
  • NOT PRIME
  • INVALID INPUT

Sample Testcases

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

Sample #1
Public sample
2
PRIME
2 is the smallest prime number.
Sample #2
Public sample
17
PRIME
17 is a prime number with no divisors other than 1 and 17.
Sample #3
Public sample
4
NOT PRIME
4 is divisible by 2, so it's not prime.
Sample #4
Public sample
100
NOT PRIME
100 is divisible by 2, 4, 5, etc., so it's not prime.
Sample #5
Public sample
1
INVALID INPUT
1 is not greater than 1, so it's not considered a prime number.

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