| | |
How to sum cubes and squares of the number input by the user
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
5. Write a program that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered by the user:
Upper Limit: 5
The sum of Squares is 55
The sum of Cubes is 225
Do this by using just one loop that generates the integers. Of course, if you really needed to calculate these sums you would use the appropriate formulas:
12 + 22 + 32 + ... + n2 = n(n+1)(2n+1)/6
13 + 23 + 33 + ... + n3 = n2(n+1)2/4
Add these formulas to your program and print out their results as well as that of the explicit summations.
Upper Limit: 5
The sum of Squares is 55
The sum of Cubes is 225
Do this by using just one loop that generates the integers. Of course, if you really needed to calculate these sums you would use the appropriate formulas:
12 + 22 + 32 + ... + n2 = n(n+1)(2n+1)/6
13 + 23 + 33 + ... + n3 = n2(n+1)2/4
Add these formulas to your program and print out their results as well as that of the explicit summations.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: clearing the char buffer ???
- Next Thread: A complex OOAD design with C++ Implementation problem !!!
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






