Menu
Coddy logo textTech

Is prime?

Lesson 6 of 20 in Coddy's Mathematical Riddles course.

A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers [wikipedia].

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

challenge icon

Challenge

Easy

Write a function isPrime that tells if a given number, <i>x</i>, is a prime?

The function will return a Boolean - True or False .

Try it yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"

int main() {
    int n;
    if (scanf("%d", &n) != 1) n = 0;
    bool r = isPrime(n);
    printf("%s\n", r ? "true" : "false");
    return 0;
}

All lessons in Mathematical Riddles

4Primes

Is prime?Prime factors

7Least common multiple

IntroductionA problem