利用大数相乘求幕

前一篇文章 里贴出了个大数相乘的代码,其实是为了解决求幕的问题。例如求5.1234的12次方,且不能丢失小数点后的结果,代码如下:

 

void get_coefficient(char* number, unsigned int exponent) { char pBuffer[100] = {0}; char pTempResult[200] = {0}; strcpy(pTempResult, number); char input[100] = {0}; char multiplid[100] = {0}; strcpy(input, number); unsigned int dot_pos_num = 0; for (size_t i = 0; i < exponent - 1; i++) { strcpy(multiplid, input); multiply_huge(pTempResult, multiplid, pBuffer); strcpy(pTempResult, pBuffer); printf("%d, %s/r/n", i+1, pBuffer); memset(pBuffer, 0, sizeof(pBuffer)); } strcpy(pBuffer, pTempResult); } int main() { char buffer[] = {"5.1234"}; get_coefficient(buffer, 12); return 0; }

你可能感兴趣的:(buffer,input)