c++中循化里面用乘方???

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:49:51
比如这样
for(int i = 0 ;i < 4; i++)
{
123 / 1 * 10 ;//这个地方 要10 的 i+1 次方 怎么弄阿?

请高手指点

pow(10,i+1)

pow(计算次方值)
相关函数 exp,log,log10

表头文件 #include<math.h>

定义函数 double pow(double x,double y);

函数说明 pow()用来计算以x为底的y次方值,即xy值,然后将结果返回。

返回值 返回x的y次方计算结果。

错误代码 EDOM 参数x为负数且参数y不是整数。

附加说明 使用GCC编译时请加入-lm。

范例 #include <math.h>
main()
{
double answer;
answer =pow(2,10);
printf("2^10 = %f\n", answer);
}

执行 2^10 = 1024.000000

#include <math.h>

using namespace std;
int main()
{
double answer;
int i;
for(i=1;i<=4;i++)
answer= 123/pow(10,i);
printf("answer = %f\n", answer);
return 0;
}

可以再用一个循环了

exp(i+1)