Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between
Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 +3 +4 + ... 9+ 10 + 11 + 12, and return the answer. However, you'll be using two different methods to do this. The first method should utilize either a for loop or a while loop, to simply add the numbers together. The second method will meanwhile use the following formula. Given some number, and told to calculate the sum from 1 to the given number, you can calculate the answer by simply calculating (X*(X + 1))/2 FOR YOUR ASSIGNMENT, you will use both of these methods to return the answer to the user, specifying which answer came from which method. In addition to simply returning the numbers however, your program MUST also mention the number of operations that occurred in calculating that answer. For this particular assignment we will only count arithmetic operations, adding, subtracting, multiplying, and dividing. So that if you perform the following: 1 + 2 +3+ 4 + 5, the result requires FOUR addition operations. For the two different methods you use, you'll need your program to return the number of operations it had to perform to reach its answer. WHAT YOU NEED TO TURN IN, are two very specific scenarios, as you'll be supplying the input yourself. First, you need to show a result in which using the mathematical formula uses fewer operations than using the looping addition. Second, you need to show a result in which using the looping addition uses fewer operations than the formula
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started