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:
parent
08fd145584
commit
0bd0cc4669
@ -0,0 +1,3 @@
|
||||
# is-prime-number/c/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 29 September 2021.
|
20
challenges/is-prime-number/solutions/c/function/solution.c
Normal file
20
challenges/is-prime-number/solutions/c/function/solution.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user