Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
sol1.c File Reference

Problem 5 solution - Naive algorithm (slowest) More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sol1.c:

Functions

static char check_number (unsigned long long n)
 Pretty naive implementation.
 
int main (void)
 Main function.
 

Detailed Description

Problem 5 solution - Naive algorithm (slowest)

See also
Faster: problem_5/sol2.c
Fastest: problem_5/sol3.c

Function Documentation

◆ check_number()

static char check_number ( unsigned long long  n)
static

Pretty naive implementation.

Just checks every number if it's devisable by 1 through 20

Parameters
nnumber to check
Returns
0 if not divisible
1 if divisible
19{
20 for (unsigned long long i = 1; i <= 20; ++i)
21 {
22 if (n % i != 0)
23 {
24 return 0;
25 }
26 }
27
28 return 1;
29}

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
37{
38 for (unsigned long long n = 1;; ++n)
39 {
40 if (check_number(n))
41 {
42 printf("Result: %llu\n", n);
43 break;
44 }
45 }
46
47 return 0;
48}
static char check_number(unsigned long long n)
Pretty naive implementation.
Definition: sol1.c:18
Here is the call graph for this function: