Answered step by step
Verified Expert Solution
Question
1 Approved Answer
programming language Mo! My x My x HW X Mic x 8 Dro x document/d/1Y9I_IpR3pbZuBgqqohkzx99kLfkn6nThiBMHzNVWNus/edit Mic x htts x Mic Dro x GD mat Tools
programming language
Mo! My x My x HW X Mic x 8 Dro x document/d/1Y9I_IpR3pbZuBgqqohkzx99kLfkn6nThiBMHzNVWNus/edit Mic x htts x Mic Dro x GD mat Tools Add-ons Help All changes saved in Drive Normal text - Arial - 11 - BIUA 4- IE E E EE 11 12 13 14 1. 61 Write a program that will calculate the sum of the first positive n cubes, 1, 8, 27, 64, ... The user will input the value of n and the program will calculate the sum two ways: (1) With a known formula (Seen below). (2) Using a loop. At the end, confirm the loop is computing the correct value by comparing the formula with the loop results. Procedure: Start with the usual standard C++ block of statements (Just as in HW 1) Step 1: This program will need user input for the value of n, so you need to declare a variable for that. Since this value must be a whole number we use: int n; Step 2: Now collect the input from the user the usual way with an appropriate message, cout >n; // Assumen > 0 to work Step 3: Compute the sum of the cubes using the formula: S = (). In order to save this sum for comparison later, declare a variable named sum. long sum; // Possible large value, so use long instead of int. sum = (n*n)*(n+1)*(n+1)/4: Step 4: Print the results from the formula, cout
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