From cbdf276b0a99999eac0648ddd4815d3991e33651 Mon Sep 17 00:00:00 2001 From: Abiel Fernandez Date: Thu, 4 Oct 2018 08:12:01 -0500 Subject: [PATCH] Fixed lucky_numbers by correctly implementing floordiv --- math/lucky_numbers.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/math/lucky_numbers.cpp b/math/lucky_numbers.cpp index 351f43f5..91a318d1 100644 --- a/math/lucky_numbers.cpp +++ b/math/lucky_numbers.cpp @@ -3,23 +3,23 @@ // algorithms.abranhe.com/math/lucky-numbers #include -#define bool int +#include /* Returns 1 if n is a lucky no. ohterwise returns 0*/ bool isLucky(int n) -{ - static int counter = 2; - +{ + static int counter = 2; + /*variable next_position is just for readability of the program we can remove it and use n only */ int next_position = n; if(counter > n) - return 1; - if(n%counter == 0) - return 0; + return true; + if(n % counter == 0) + return false; /*calculate next position of input no*/ - next_position -= next_position/counter; + next_position -= floor(next_position / counter); counter++; return isLucky(next_position); @@ -35,3 +35,4 @@ int main() printf("%d is not a lucky number.", x); getchar(); } +