Created
April 27, 2014 02:50
-
-
Save rpicard/11336548 to your computer and use it in GitHub Desktop.
Finally started to get some intuitive understanding of logarithms so I put it into code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
int base = atoi(argv[1]); | |
int value = atoi(argv[2]); | |
int i = 0; | |
# keep dividing value by base to reverse the exponent processes | |
while(value != 1) { | |
# doesn't handle fractions | |
if (value % base) { | |
return -1; | |
} | |
# count how many divides it takes to reverse the process | |
value = value / base; | |
i++; | |
} | |
printf("%d\n", i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment