.net营销网站开发,网站搜索引擎收录,施工企业资产核算的具体内容,网站用什么语言好参考链接
输入描述:
多组测试用例#xff0c;请参考例题的输入处理 输入每行一个浮点数 R 其中0.0 R 99.999#xff0c; 一个整数 n 其中0 n 25
输出描述:
输出R的n次方
输入例子1:
95.123 12 0.1 1
输出例子1:
548815620517731830194541.89902534…参考链接
输入描述:
多组测试用例请参考例题的输入处理 输入每行一个浮点数 R 其中0.0 R 99.999 一个整数 n 其中0 n 25
输出描述:
输出R的n次方
输入例子1:
95.123 12 0.1 1
输出例子1:
548815620517731830194541.899025343415715973535967221869852721 0.1
解题思路
因为涉及到的操作数可能会非常大超出c语言本身能表示的数的大小以及精度所以思路大概是这样的
1、对输入的处理因为第一个书可能是小数小数相乘我们要记录下小数点的位置所以第一个输入按字符串格式读入通过比较找出小数点的位置。
2、对R的处理小学时我们学小数的计算的时候都是先转换成整数记下两个乘数的小数点的位置最后再加上小数点所以先把R处理成整数并通过小数点的位置计算出最后结果的小数位数。
3、计算计算按大数计算的方式进行计算。
4、输出输出的时候要检查最后结果是否小于1小于1的话要补充足够的0
#include stdio.h
#include string.hint len; //total length of exponentiation result.
int product[126] {0}; // storing result, at most length 5*25 1 126void multiply(int a[], int n)
{int i;int carry 0; // a carry number in multiplyingfor (i 0; i len; i){int temp a[i]*n carry;a[i] temp % 10;carry temp / 10; }while (carry){a[i] carry % 10;carry / 10;}len i;
}int main(int argc, char* argv[])
{int n; // power nchar s[6]; // real number R, at most the length is 6while (scanf(%s %d, s, n) ! EOF){int position0, i0, num0, j0;for (i0; istrlen(s); i) {if (s[i] .){position (strlen(s) - 1 - i) * n; // calculate decimal point position after R^n}else{num num*10 s[i] - 48; // transfer float to integer} }// product calculation product[0]1;len 1;for (i 0; i n; i){multiply(product, num);}// format outputif (len position) // product is less than 1{printf(0);printf(.); // print decimal pointfor (i0; iposition-len; i){printf(0); // print zero between decimal point and decimal}j 0;//while (product[j] 0) // trim trailing zeros//{// j;//}for (ilen-1; ij; i--){printf(%d, product[i]);}} else{j0;while (product[j]0 jposition) // trim trailing zeros{j;}for (ilen-1; ij; i--){if (i1 position) // cause index in C language starts from 0{printf(.);}printf(%d, product[i]);}}printf(\n);}
}