Given the task:

Find the term of the sequence given by the formula Bi = 4 * Bi-1, for i> 1. The values ​​of the first term in the sequence are entered by the user.

Pascal code was created to solve this problem, what would it look like in C ++?

Code example:

function B(a:real;i:integer):real; begin if i=1 then B:=a else B:=4*B(a,i-1); end; var a:real; n:integer; begin write('Первый член a='); readln(a); write('n='); readln(n); writeln(B(a,n):0:3); end. 
  • yes, in the same way, only instead of begin...end will be braces {} and var should not be written - slippyk
  • Give your attempt to implement this code, then we can point out errors to you. At the moment it looks like a learning task. - Komdosh

1 answer 1

Now again zaminusyut, but I suffer for the love of mathematics :)

 double B(double a, unsigned int n){ return a*pow(4,n-1); } 

Cool C ++ language, right? :)

  • and check where? - Komdosh
  • @Komdosh What i> = 1? :) - Harry
  • aha how without her - Komdosh
  • @Komdosh And the TC does not have it either :( Only for equality. - Harry
  • one
    @Komdosh Personally, I understood the task so that the data i <= 1 guaranteed not to be entered. - Harry