Exercise 2 – Sum of Sequential Integers Write a program that asks the user for N and then sum all the integers (inclusive) between 1 and N. Enter N:10Sum = 55 %3D Do this in a loop that counts up 1 to N and in each iteration adds the current count to the sum. Another way to calculate the same thing is through a formula: sum = (n*(n+1))/2 Modify your program so that it calculates the sum both ways: Enter N: 10Loop Sum = 55 Formula Sum = 55 %3D You might worry that the formula will lead to integer division problems. But it works as is. Why? (Hint: think about even and odd.) The sum of sequential integers 1 to N is called a triangle number. See the exercises for chapter 25.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question

Please type and execute this java program and also need an output for this java program. Need as soon as possible thank you.

Exercise 2 – Sum of Sequential Integers
-
Write a program that asks the user for N and then sum all the integers (inclusive)
between 1 and N.
Enter N:10Sum
= 55
Do this in a loop that counts up 1 to N and in each iteration adds the current count to
---------------------------------+-
the sum.
Another way to calculate the same thing is through a formula:
sum = (n*(n+1))/2
Modify your program so that it calculates the sum both ways:
Enter N:
10Loop Sum = 55
%3D
Formula Sum = 55
%D
You might worry that the formula will lead to integer division problems. But it works
as is. Why? (Hint: think about even and odd.)
The sum of sequential integers 1 to N is called a triangle number. See the exercises
for chapter 25.
Transcribed Image Text:Exercise 2 – Sum of Sequential Integers - Write a program that asks the user for N and then sum all the integers (inclusive) between 1 and N. Enter N:10Sum = 55 Do this in a loop that counts up 1 to N and in each iteration adds the current count to ---------------------------------+- the sum. Another way to calculate the same thing is through a formula: sum = (n*(n+1))/2 Modify your program so that it calculates the sum both ways: Enter N: 10Loop Sum = 55 %3D Formula Sum = 55 %D You might worry that the formula will lead to integer division problems. But it works as is. Why? (Hint: think about even and odd.) The sum of sequential integers 1 to N is called a triangle number. See the exercises for chapter 25.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning