现在的位置: 首页 > 综合 > 正文

求X的N次乘方

2012年01月13日 ⁄ 综合 ⁄ 共 421字 ⁄ 字号 评论关闭
float power(float x,int n)
{
 float t=1;
 for(int i=1;i<=n;i++)
   t=t*x;                                      /*1*x*x*x*...*x共乘n次*/
 return t;
}

#include <stdio.h>
#include 
<conio.h>
float power(float,int);
void main()
{
 
float x,t;
 
int n;
 clrscr();
 printf(
"Please input x,n number:");
 scanf(
"%f,%d",&x,&n);
 t
=power(x,n);
 printf(
"The max number is :%6.2f",t);
}


float power(float x,int n)
{
 
float t=1;
 
for(int i=1;i<=n;i++)
   t
=t*x;
 
return t;
}

抱歉!评论已关闭.