mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 06:49:36 +03:00
bb6c62aa62
* rename existing code as sol3 * Added naive implementation for Problem 5 * Added a solution for Euler Problem 5 with easy improvements * rename new files * code formatting * update documentations * fix docs * updating DIRECTORY.md Co-authored-by: buffet <niclas@countingsort.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
49 lines
856 B
C
49 lines
856 B
C
/**
|
|
* \file
|
|
* \brief [Problem 5](https://projecteuler.net/problem=5) solution - Naive
|
|
* algorithm (slowest)
|
|
*
|
|
* \see Faster: problem_5/sol2.c
|
|
* \see Fastest: problem_5/sol3.c
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
/** Pretty naive implementation. Just checks every number if it's devisable by 1
|
|
* through 20
|
|
* @param n number to check
|
|
* @returns 0 if not divisible
|
|
* @returns 1 if divisible
|
|
*/
|
|
static char check_number(unsigned long long n)
|
|
{
|
|
for (unsigned long long i = 1; i <= 20; ++i)
|
|
{
|
|
if (n % i != 0)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* @brief Main function
|
|
*
|
|
* @return 0 on exit
|
|
*/
|
|
int main(void)
|
|
{
|
|
for (unsigned long long n = 1;; ++n)
|
|
{
|
|
if (check_number(n))
|
|
{
|
|
printf("Result: %llu\n", n);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|