File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ // C++ implementation of Juggler Sequence
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ // This function prints the juggler Sequence
6+ void printJuggler (long long n)
7+ {
8+ long long a = n;
9+
10+ // print the first term
11+ cout << a << " " ;
12+
13+ // calculate terms until
14+ // last term is not 1
15+ while (a != 1 )
16+ {
17+ long long b = 0 ;
18+
19+ // Check if previous term
20+ // is even or odd
21+ if (a % 2 == 0 )
22+
23+ // calculate next term
24+ b = floor (sqrt (a));
25+
26+ else
27+
28+ // for odd previous term
29+ // calculate next term
30+ b = floor (sqrt (a) *
31+ sqrt (a) * sqrt (a));
32+
33+ cout << b << " " ;
34+ a = b;
35+ }
36+ }
37+
38+ // Driver Code
39+ int main ()
40+ {
41+ printJuggler (37 );
42+ cout <<" \n " ;
43+ printJuggler (9 );
44+ return 0 ;
45+ }
46+
47+
You can’t perform that action at this time.
0 commit comments