DECLARE @CountOfNumbers int = 30
DECLARE @Fibonacci TABLE(OrderNo int, FibonacciNumber bigint)
INSERT INTO @Fibonacci(OrderNo,FibonacciNumber)
VALUES
(1,0), -- 1. sayı = 0
(2,1) -- 2. sayı = 1
DECLARE @i int = 3, -- 3 den başlatalım, 1. ve 2. yi sayıları tabloya ekledi
@F1 bigint = 0,
@F2 bigint = 1,
@F bigint
WHILE @i<=@CountOfNumbers BEGIN
SET @F = @F1 + @F2
INSERT INTO @Fibonacci(OrderNo,FibonacciNumber) VALUES(@i,@F)
SET @F1 = @F2
SET @F2 = @F
SET @i+=1
END
SELECT * FROM @Fibonacci
1 yorum:
olur mu diye denedim oldu :)
declare @i int = 0,
@i1 int = 1,
@i2 int = 0,
@step int = 0
declare @p int = 7
declare @dummy table (d int)
while @step <= @p begin
insert into @dummy values(@step)
set @step +=1
end
select @i = @i1 + @i2
, @i2 = @i1
, @i1 = @i
from @dummy
select @step step, @i fibo
Yorum Gönder