0

What formula shoul i use?

In the task there is given number n, which is the number of roots and formula looks like sqrt(2+sqrt(2+...)). And my code looks like: #include <iostream> #include <cmath> using namespace std; int main() { int n, i; float c; cin>>n; i=0; while(i<n){ c=sqrt(2+sqrt(2)); i++; } cout<<c ; return 0; } What should I do so the code was right? https://code.sololearn.com/cTt8609x7Rwh/?ref=app

19th Sep 2021, 6:20 AM
Aruzhan
5 Answers
+ 4
c=sqrt(2+c);
19th Sep 2021, 7:14 AM
Simba
Simba - avatar
+ 2
Error is there in 13th line Write cout<<c; instead of "cout c ;"
19th Sep 2021, 6:57 AM
Saurabh
Saurabh - avatar
+ 1
I didn't get you Aruzhan , what did you mean? kindly elaborate
19th Sep 2021, 7:04 AM
Saurabh
Saurabh - avatar
0
Thanks, but how to calculate this formula? Like input: 1 Output: 1.4 Input: 2 Output: 1.8
19th Sep 2021, 7:00 AM
Aruzhan
0
It should calculate n roots, like if input is 1, then c=sqrt(2), so the output is 1.4 If input is 2, then c=sqrt(2+sqrt(2)), so the output is 1.8 and so on
19th Sep 2021, 7:06 AM
Aruzhan