need an algorithm for the Fibonacci sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
which language?
portuguese or english
LOL.. Didnt meant that. Which computer language? Sou portugues já agora
In c++ for example, it would be something like: int i, l; int j, k=1; for (i=0; i<100; i++) { l = j + k; cout << l; j = k; k = l; }}
pascal
Pascal: program fibo; var result : longint; num,i, error: integer; strnum: string; function fib(n : integer) : longint; begin if n <= 2 then fib := 1 else fib := fib(n-2) + fib(n-1); end; begin if ParamCount = 0 then begin writeln('Enter integer:'); readln(strnum); val(strnum,num,error); end else begin val (ParamStr(1), num, error); end; for i := 1 to num do begin result:= fib(i); writeln(i, ' : ', result); end; end.
thanks Dalvoron and Diogo
Join our real-time social learning platform and learn together with your friends!