當前位置:編程學習大全網 - 電腦編程 - C語言編程題:輸入x和n的值,編寫程序計算f(x,n)=x-x^2+x^3-x^4+...x^n(-1)^n-1,其中用函數power(x,n)求x^n

C語言編程題:輸入x和n的值,編寫程序計算f(x,n)=x-x^2+x^3-x^4+...x^n(-1)^n-1,其中用函數power(x,n)求x^n

# include <math.h>

double power(double x, int n)

{

int i = 1, index = 0 ;

double result = 0 ;

for(index = 1 ; index <= n ; index++)

{

result += i * pow(x, index) ;

i = -i ;

}

return (result) ;

}

  • 上一篇:機明長短刀怎麽設置
  • 下一篇:高中信息技術考試的內容是什麽?
  • copyright 2024編程學習大全網