1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 11:09:07 +01:00
CodeWars/7kyu/most_digits/solution.c
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

20 lines
418 B
C

#include <stddef.h>
#include <math.h>
int find_longest(int *numbers, size_t numbers_size)
{
double digits = floor(log10(fabs(numbers[0])));
int number = numbers[0];
for (size_t i = 1; i < numbers_size; i++)
{
double digits_now = floor(log10(fabs(numbers[i])));
if (digits_now > digits)
{
digits = digits_now;
number = numbers[i];
}
}
return number;
}