Thread: FOR cycle problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I'm pretty sure you wrote hatvany() wrong. alap *= alap; doesn't really help much.

    You want to do, for example:
    res = 1;
    alap = 2;
    exp = 3;
    res *= alap;
    --exp;
    res *= alap;
    --exp;
    res *= alap;
    --exp;

    By now res is 8, as you'd expect, and exp is 0. Perhaps a for loop that tests exp repeatedly is what you actually want.

    Also you still need to initialize the answer to the whole calculation to 0 or 1 (depending on if you add or multiply, respectively).
    Last edited by whiteflags; 11-12-2018 at 01:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with while cycle
    By Lima in forum C Programming
    Replies: 5
    Last Post: 10-29-2010, 09:57 AM
  2. Cycle
    By Gordon in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2007, 10:58 AM
  3. Cycle counters
    By cosmo1996 in forum C Programming
    Replies: 3
    Last Post: 08-14-2007, 09:33 AM
  4. How to Cycle Through Structs
    By Grantyt3 in forum C++ Programming
    Replies: 13
    Last Post: 08-27-2005, 04:29 PM
  5. Euler Cycle
    By nickwokabi in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2005, 09:54 AM

Tags for this Thread