|
-
Nov 17th, 2002, 05:50 PM
#1
Thread Starter
New Member
calculation using powers ?
Hi any Tips, i am not looking for the full code as i am trying to learn it myself.
the sum is 3 to power of 3, minus 5 to power of 5, plus 7 to pow of 7, minus 9 to pow 9, ect ect its reoccuring going up in powers adding one sum then minus the next ect till I reach the number I want.
would I have 2 separate lines i.e
i = 3 raised to the power 3 , then 7 rasied to power of 7 ect
to give me the plus
then would i have
j = 5 to pow 5 ect to give me minus
or am I going down the wrong track
thanks if you can advise
as I would like to solve it before I get my pension
-
Nov 18th, 2002, 05:48 AM
#2
Not quite sure what you want. Is this it?
Code:
int i=0, j=3, sum=0;
while(sum < numberYouWantToReach) {
sum += (i%2)?(-(Math.pow(j,j))):(Math.pow(j,j));
i++; j += 2;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|