//(1)定义函数(x,n),计算x的n次幂#include "stdio.h"
double f(double x,int n)
{
double s=1.0;
int i;
for(i=1;i<=n;i++)
{
s=s*x;
}
return s;
}
void main()
{
double x;
int n;
printf("请输入x:");
scanf("%lf",&x);
printf("请输入n:");
scanf("%d",&n);
printf("%lf的%d次幂等于%lf\n",x,n,f(x,n));
}运行截图: