0
Does ma code work properly??
Hi folks , i made a sequence of numbers which i-th number of sequnce can be calculate by recrusive function . This is d sequnce : L(1)=1 , L(2k)=2×L(k) L(2k+1)=L(2k)-1 . https://code.sololearn.com/c4Df1ILZQ0Je/?ref=app Does it work properly??
5 ответов
+ 1
Ali_combination 1 is correct. You can check very easily, once you understood the behavior of the sequence. It is easier than it looks at first. Take my code to print the sequence up to n, then you will see
Btw you asked for a recursive solution but your code is iterative
0
Seems ok. But you can check yourself by writing down the start of the sequence and comparing the output.
Change the output to this to get the sequence up to n:
for(int i=0;i<n;i++){
cout<<i<<"\t"<<l[i]<<"\n";
}
0
Benjamin Jürgens Thank you so much . Now , as u said , we can calculate one of the numbers in the sequence , for example 2047-th one . My code prints 1 . Is it true by your code or your own idea?
0
Except for the first and second numbers , all next numbers are made like this : 2^(n-1) -1 , 2^(n-1) -2 , ... ,3 , 2 , 1 , 2^n
0
Benjamin Jürgens That's right , I appreciate your precious help gentleman🙏