Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 4: But I haven't taken Calculus yet! OK - we admit, this one might look nasty, but read on because it's not that bad.

image text in transcribed
image text in transcribed
Program 4: But I haven't taken Calculus yet! OK - we admit, this one might look nasty, but read on because it's not that bad. One of the things that computing folks do A LOT (especially CS students) is analyze how long a program takes to run. In the first step, something might take 1 unit of CPU time. The second step might take 2, the third 3 and so on. Mathematically, that would be expressed by the "summation" operator as this: This is may look complex, but all it's saying is that i goes from 1 to n and you sum all those numbers together. So, if (n = 10). i = 1 + 2 +3 +4 +5 +6 + 7 + 8 + 9 + 10 = 55 Fortunately, this reduces to a simple formula. When summing numbers from 1-n, the sum is: (n+1)*n/2 Why? It's all in how you "pair the numbers together. In the example above, we could pair (1+10)=11, (2+9)=11, (3+8)=11 and so on. That is, we have n/2 "pairs" of (n+1). Your task is, without using a loop (which we haven't covered yet), to write a program that asks the user for a number, then prints out the sum of 1 to that number. If you use a loop, you will receive no credit Sample Output: Enter a number: 3 The sum of the numbers between 1 and 3 is 6 Sample Output #2: Enter a number: 10 The sum of the numbers between 1 and 10 is 55 Sample Output #3: Enter a number: 15 The sum of the numbers between 1 and 15 is 120

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago