Answer to Question #267271 in Visual Basic for Nicole

Question #267271

Given three integers j, k and m


Build a function (in any development language) called SeqSummation, that calculates the sequence of summation as per:


j + (j + 1) + (j + 2) + (j + 3) + … + k + (k − 1) + (k − 2) + (k − 3) + … + m


Explanation: increment from j until it equals k, then decrement from k until it equals m.


Function Description


Create the function SeqSummation.


SeqSummation takes the following parameter(s):


• j integer


• k integer


• m integer


Program Output


• the value of the sequence sum


Example


• SeqSummation (5,9,6)


• i = 5, j = 9, k = 6


• Sum all the values from i to j and back to k: 5 + 6 + 7 + 8 + 9 + 8 + 7 + 6 = 56.


• Output: 56



Question



1
Expert's answer
2021-11-18T06:46:27-0500
Imports System.IO


Module Module1




    Function SeqSummation(ByVal j As Integer, ByVal k As Integer, ByVal m As Integer)
        Dim sum As Integer = 0
        For i = j To k
            sum += i
        Next
        For i = k - 1 To m Step -1
            sum += i
        Next
        Return sum
    End Function
    Sub Main()
        Console.Write("Enter j: ")
        Dim j As Integer = Integer.Parse(Console.ReadLine())
        Console.Write("Enter k: ")
        Dim k As Integer = Integer.Parse(Console.ReadLine())
        Console.Write("Enter m: ")
        Dim m As Integer = Integer.Parse(Console.ReadLine())
        Console.WriteLine("Sum = " + SeqSummation(j, k, m).ToString())
        Console.ReadLine()
    End Sub
End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS