Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions math/lucky_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
// algorithms.abranhe.com/math/lucky-numbers

#include <stdio.h>
#define bool int
#include <math.h>

/* 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);
Expand All @@ -35,3 +35,4 @@ int main()
printf("%d is not a lucky number.", x);
getchar();
}