We go through a clean mathematical answer, because I think you are looking for:
#include <math.h> #include <stdio.h> main() { long long mynum = 2987612345; long long firstDigitValue; int firstDigit; char *names[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; while (mynum > 0) { firstDigit = (int) (mynum/pow(10,(int)log10(mynum))); firstDigitValue = firstDigit * pow(10,(int)log10(mynum)); mynum -= firstDigitValue; printf("%s ", names[firstDigit]); } printf("\n"); }
And then its launch causes:
two nine eight seven six one two three four five
It should work with any size number that can process for a long time (in other languages ββor with a large library of numbers in C, it can handle something arbitrarily large).
Now ... I'm not sure that using log10 and pow is the fastest. But this is the most interesting :-)
source share