Thread: FOR cycle problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by whiteflags View Post
    I'm pretty sure you wrote hatvany() wrong. alap *= alap; doesn't really help much.
    Well, but it's inside the loop -- this is binary exponentiation. So x^9 = x^8 * x (since that's the binary representation of 9), and the repeated squaring of alap gives alap^2, alap^4, alap^8, etc., so that when the right-most bit of the power is one the correct power of alap gets multiplied in.

  2. #2
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Location
    Berlin
    Posts
    105
    Quote Originally Posted by gyilki
    . . . i had to write an own power, cuz cannot use math.h
    Why? The function exp() need "math.h". You use the name of a C function for a variable (int exp). . . that's not well.

    C library function exp()

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Kernelpanic View Post
    Why?
    Teachers are weird. (But yes, using a reserved name for a function parameter is a Bad Idea.)

  4. #4
    Registered User
    Join Date
    Nov 2018
    Posts
    5
    Solved, i rewrote the whole code and it works! Thanks for helping me guys!

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