Description
输入一个正整数 repeat (0<’repeat<10),做repeat 次下列运算:
读入 1 个正实数x 和1 个正整数 n(n<=10),计算并输出x 的n 次幂(保留2 位小数)。
Input
见sample
Output
见sample
Sample Input
2
1.5 2
2.0 10
Sample Output
2.25
1024.00
#include<string.h>
#include<stdio.h>
int main()
{
int repeat;
int x,a;
double s,b;
scanf("%d",&repeat);
for(int aa=0;aa<repeat;aa++)
{
scanf("%lf%d",&b,&a);
s=1;
for(int x=0;x<a;x++)
{
s=s*b;
}
printf("%.2f\n",s);
}
return 0;
}
本题要求求一个数的n次幂.因为对math头文件不甚了解,故没有使用函数,而是向一个初始值为1的变量上乘n个数,达到求幂的目的.