1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-10-29 22:17:23 +01:00

feat(solutions): add is-prime-number/c/function

This commit is contained in:
Divlo 2021-09-29 09:31:49 +02:00
parent 08fd145584
commit 0bd0cc4669
No known key found for this signature in database
GPG Key ID: 6F24DA54DA3967CF
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# is-prime-number/c/function
Created by [@Divlo](https://github.com/Divlo) on 29 September 2021.

View File

@ -0,0 +1,20 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
bool is_prime_number(int number) {
for (int iteration = 2; iteration < number; iteration++) {
if (number % iteration == 0) {
return false;
}
}
return true;
}
int main() {
int number;
scanf("%d", &number);
bool is_prime = is_prime_number(number);
printf("%s\n", is_prime ? "true" : "false");
return EXIT_SUCCESS;
}