Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to write the code for problem 2, make sure it work Problem 2: The following code is an example of a FOR

Please help me to write the code for problem 2, make sure it work

Problem 2: The following code is an example of a FOR loop. The function finds the sum from 1 + 2 + 3 + x, where x is the input value. Paste the code below into Excel and modify the code so that it instead it adds 12 + 22 + 32 + x2. Extra credit: Have it check to make sure that x is a positive integer before it does the loop, and tell the user that the input is invalid. Paste your updated code here.

Function LoopSum(x)

'this function takes a positive integer input and finds the sum from 1 to that positive integer 'for example, for input x = 5, the output will be 1+2+3+4+5, that is it will output the number 15.

LoopSum = 0 'start the output variable with a value of 0

For k = 1 To x

LoopSum = LoopSum + k 'each time it goes through the for loop, it adds the current value of k

Next k

End Function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

Analyze data in the order-to-cash process.

Answered: 1 week ago