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.
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
Related questions
Question
Please type and execute this java
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning