Challenge: Find out if the Given Number is Prime

Test your understanding by solving a simple challenge in this lesson.

Problem statement

You are given a number. Your task is to find whether the given number is prime or not.

πŸ“ A number is prime if it is only divisible by 1 and itself.

πŸ“ 1 is not a prime number, and 2 is the only even prime number.


We have already initialized the variable number at the backend.


  • If the given number is prime, you should print prime to the console.

  • If the given number is not prime, you should print not prime to the console.

Sample input

int number = 31;

Sample output


Coding exercise

Before diving directly into the solution, try to solve it yourself. Then check if your code passes all the test cases.

πŸ“ Please use the variable number for the input and print your output to the console, or your code will not execute.

Good luck! πŸ‘

Get hands-on with 1200+ tech skills courses.