From 349d9b1ddacc2ea87662f8146c4a468139ecbdbe Mon Sep 17 00:00:00 2001 From: AJANRAJ <35831352+AJANRAJ@users.noreply.github.com> Date: Thu, 4 Oct 2018 17:06:40 +0530 Subject: [PATCH] Create lucky.cpp --- lucky.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lucky.cpp diff --git a/lucky.cpp b/lucky.cpp new file mode 100644 index 00000000..953fa396 --- /dev/null +++ b/lucky.cpp @@ -0,0 +1,33 @@ +#include +#define bool int + +/* Returns 1 if n is a lucky no. ohterwise returns 0*/ +bool isLucky(int n) +{ + 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; + + /*calculate next position of input no*/ + next_position -= next_position/counter; + + counter++; + return isLucky(next_position); +} + +/*Driver function to test above function*/ +int main() +{ + int x = 5; + if( isLucky(x) ) + printf("%d is a lucky no.", x); + else + printf("%d is not a lucky no.", x); + getchar(); +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy