/* * rtext.c by Cobi * Extracts a root of a number by brute force. * gcc rtext.c -o rtext -lm */ /* * We need this library for printf and fprintf. */ #include /* * We need this library for atoi and malloc. */ #include /* * We need this library for exp10. */ #include /* * We need this library for strcat. */ #include /* * Our main function. */ int main (int argc, char **argv) { /* * We define some variables. */ char **ret = 0; unsigned long root = strtoll(argv[1],ret,0); ret = 0; unsigned long places = strtoll(argv[3],ret,0); ret = 0; long double initial = strtol(argv[2],ret,0); long double value = 0; signed long long place = 0; unsigned long nplace = 1; signed long long temp = (signed long long) initial; if (temp > 0) { while (temp >= 10) { temp = temp / 10; place++; } } else { while (temp < 0) { temp = temp * 10; place--; } } temp = 0; char imaginary = 0; /* This really should be a boolean, but there is no boolean in C. */ ret = 0; if (strtoll(argv[1],ret,0) < 0) { imaginary = 1; } ret = 0; while (nplace < places) { while (powl(value,root) < initial) { value += pow(10,place); } value -= pow(10,place); place--; nplace++; } char temp2[100]; if (place < 0) { place = 0 - place; } snprintf(temp2,sizeof(temp2),"%%.%LdLg\n",place); printf(temp2,value); }