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
EasyWrite 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;
}