Thread: alternatives to pow()

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    7

    alternatives to pow()

    Hello,

    I'm working on an assignment that requires the user to input a number, and then another number to raise the first one by (like pow() ). The product is then displayed. By the way, this would be incredibly easy with the pow function, but I am not allowed to use it.

    I am stumped.

    I am not asking anyone to write this for me. In fact, I request that if you offer a solution, don't even give me a code example. Just give me a bit of direction on how to accomplish this with looping (ie what type of looping to use, etc).

    Any feedback is appreciated, I'm pretty stuck.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well is it integer based math? If so just use a simple for loop after the input of the second number.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    7
    yes, it is interger based. Whole numbers only.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    You could use a for loop that counts from 1 to the number of times the user wants to multiply by (the power),

    Have a variable holding the running total, and just multiply the total (good Idea to initialise it as 1) by the base number each time through the loop.

    That'd be my first guess...hope it helps

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    7
    I got it. Yes, that helped a lot especially considering I was messing with a total while I read your reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's the difference between pow() vs shift?
    By Overworked_PhD in forum C Programming
    Replies: 9
    Last Post: 01-06-2008, 01:04 PM
  2. Help with pow()
    By jedi_jinn in forum C Programming
    Replies: 7
    Last Post: 10-09-2006, 02:17 AM
  3. trying to use pow()
    By Mikecore in forum C Programming
    Replies: 9
    Last Post: 10-09-2005, 06:30 PM
  4. pow function returns wrong value
    By ckbales in forum C Programming
    Replies: 5
    Last Post: 02-01-2003, 09:46 PM
  5. Problem with pow()
    By RMacFly in forum C Programming
    Replies: 4
    Last Post: 09-18-2001, 11:54 AM