For this problem, you need to study the For Next Loop mentioned in Chapter 14 Th
ID: 3909409 • Letter: F
Question
For this problem, you need to study the For Next Loop mentioned in Chapter 14 The sum of the first n positive integer numbers is given by the formula n-(n+1 Write a function which will accept as argument a positive integer number, n, and will return the sum of the first n positive integer numbers. The function will calculate the sum using a For .. Next Loop, not using the above formula. Compare the result of your function to that obtained using the above formula in Excel when n is equal to 10 and when n is equal to 100. Are they the same? 1. 2.Explanation / Answer
Answer 1:
Private Function MySum (ByVal n As Integer)
Dim s as Integer
s = 0
For i = 1 To n
s = s + i
Next i
MySum = s
End Function
==============
Answer 2)
Using excel, the sum for n = 10 is 55 and for n = 100 is 5050
It matches with the functions output
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.