Previous Next
0 / 18
Module DEMO-32-90DEMO-C-32

Primality Tester

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a function int isPrime(int n) that returns 1 if n is a prime number, and 0 otherwise.

A prime number is greater than 1 and has no divisors other than 1 and itself.

Constraints

n

Input Format

A single integer.

Output Format

1 or 0.

Sample Testcases

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

Sample #1
Public sample
2
1
2 is prime.
Sample #2
Public sample
4
0
4 is not prime.
Sample #3
Public sample
1
0
1 is not prime.

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