Skip to content

Commit 7143642

Browse files
authored
Juggler_Sequence.cpp
C++ implementation of Juggler Sequence
1 parent 2aae9de commit 7143642

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Juggler_Sequence.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+

0 commit comments

Comments
 (0)