Basic Exercise
Create an application that will calculate the output of the function $S=N+N^{2}+N^{3}+...+N^{M}$ where $N$ and $M$ are positive integers inputted by the user
Remember that in most cases there is more than one way to solve the exercise.
Hint: Create a Loop that runs from 1 to $M$. Every new term equals $N$ raised to the $i$^th power
We start by defining the arguments of the function and the output data type
Function SuMPoW(N As Long, M As Long) As Double
We declare the variables
Dim i As Long
Dim Prog As Double
We create a For...Next loop from 1 to $M$ where the number of the iteration equals to the exponent
For i = 1 To M
Prog = Prog + (N) ^ i
Next i
Finally, we define the output of the function as the "Prog" variable
SuMPoW = Prog
Function SuMPoW(N As Long, M As Long) As Double
Dim i As Integer
Dim Prog As Double
For i = 1 To M
Prog = Prog + (N) ^ i
Next i
SuMPoW = Prog
End Function
SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.
Excel ® is a registered trademark of the Microsoft Corporation.
© 2019 SuperExcelVBA | ABOUT
Thank you for contributing. A message was sent reporting your comment.