943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1176
  • C++ RSS
Feb 15th, 2009
0

How to sum cubes and squares of the number input by the user

Expand Post »
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.
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
C++.java is offline Offline
7 posts
since Dec 2008
Feb 15th, 2009
0

Re: How to sum cubes and squares of the number input by the user

Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Feb 15th, 2009
1

Re: How to sum cubes and squares of the number input by the user

The problem practically gives away what you need to do. Have you been to class at all? Taken any notes? All you need is a simple (very simple) loop, a few counters, and the basic math knowledge to perform squares and cubes. Oh, and some form of getting input (also quite simple!).
Reputation Points: 128
Solved Threads: 43
Posting Whiz
death_oclock is offline Offline
389 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: clearing the char buffer ???
Next Thread in C++ Forum Timeline: A complex OOAD design with C++ Implementation problem !!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC