Created
March 25, 2014 13:23
-
-
Save trengrj/9761676 to your computer and use it in GitHub Desktop.
compute first 1000 hamming numbers
This file contains hidden or 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
/* | |
* Program to compute the first 1000 Hamming numbers. | |
* i.e. numbers of the form 3**i4**j5**k. | |
* Challenge from programming Praxis: | |
* http://programmingpraxis.com/2011/08/30/hamming-numbers/ | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAX 1000 | |
void hamming_number(int n, int current_mult) { | |
if (n < MAX) { | |
printf("%d\n", n); | |
} | |
else { | |
return; | |
} | |
switch (current_mult) { | |
case 2 : hamming_number(n*current_mult, 2); | |
case 3 : hamming_number(n*current_mult, 3); | |
case 5 : hamming_number(n*current_mult, 5); | |
} | |
} | |
int main(int argc, const char *argv[]) { | |
hamming_number(1,2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment