Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics
Viewing all articles
Browse latest Browse all 4901

Fibonacci numbers using a function.

$
0
0
Hello,I am calculating the first 20 Fibonacci numbers using a function,but getting wrong answer.The condition is to write a function not a procedure. here is my try,help me.create function fn_fibo(@end int)returns intasbegindeclare @a int, @b int,@fib intset @a = 0set @b = 1set @fib = 0while @fib < @endbegin set @fib = @a + @b set @a = @b set @b = @fibendreturn @fibendselect dbo.fn_fibo(20)

Viewing all articles
Browse latest Browse all 4901

Trending Articles