 We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

## 4 replies

Last post Aug 07, 2009 06:31 AM by deshjyoti

Dear All,

I want code for following logic,

1+2+3+5+8+13 =  32

thnks

vb.net .NET visual basic 2005 visua basic.net vb.net1.1 vb.net2.0 vb.net chat Visual Basic .NET vb.net expression Visual Basic.NET 2008

• ### Re: Logic For Addtion

Hi,

Can you provide more details on your requirement? This looks like a simple addition.

Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
• ### Re: Logic For Addtion

Hi

I want code for this in vb.net.

I just want code for that how to do ?

thnks

• ### Re: Logic For Addtion

Aug 07, 2009 06:11 AM|Shengqing Yang - MSFT|LINK

#### hspatil

Dear All,

I want code for following logic,

1+2+3+5+8+13 =  32

thnks

Hi,

Please refer to this function that returns the sum of this sequence with the only input as the length of the sequence.

```Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write(SumOfFibonacci(6))

End Sub

Protected Function SumOfFibonacci(ByVal n As Integer) As Integer
If n <= 0 Then Throw New Exception("n must be a positive number")
Dim f1 As Long = 1
Dim f2 As Long = 2
Dim temp As Long

If n = 1 Then Return f1

Dim sum As Long = 0
For i As Integer = 1 To n
sum = sum + f1
temp = f2 : f2 = f2 + f1 : f1 = temp
Next
Return sum

End Function```

Since this is the very famous Fibonacci Number, which you can refer to this link for more information: http://en.wikipedia.org/wiki/Fibonacci_number, thousands of functions doing the same task can be found from Google. You may have a try yourself with this search link: http://www.google.com/search?hl=en&newwindow=1&q=fibonacci+sum+code&aq=f&oq=&aqi.

Best Regards,
Shengqing Yang

Please mark the replies as answers if they help or unmark if not.
Microsoft One Code Framework
• ### Re: Logic For Addtion

http://goldennumber.net/fibonser.htm

Dim i As Integer = 0
Dim j As Integer = 1
Dim k, l As Integer

Dim str As String
str = i & "," & j
For l = 0 To 10
k = i + j
i = j
j = k
str = str & "," & k
Next
MsgBox(str)