Results 1 to 2 of 2

Thread: calculation using powers ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    liverpool
    Posts
    9

    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

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width