[問題] pow的用法
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
問題(Question):
pow的用法有特別的限制嗎
%f是float 那什麼是double
預期的正確結果(Expected Output):
我是想用泰勒展開算sinx=x-x^3/3!+x^5/5!......(-1)^n*x^(2n+1) / (2n+1)!
我n是用15代
錯誤結果(Wrong Output):
error C2062: 未預期的型別 'int'
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
void main()
{ int s=1,i=1,j=1;
double y, x, sum=0;
const double pi=3.1415926;
cin>>x;
y=x*pi/180;
for(i=1;i<=31;i+=2)
{ for(j=1;j<=31;j++)
{s=s*j;}
sum=sum+int pow(-1,15)*double pow(y,31)/s;
s=1;}
printf("%f\n",sum); sum=0;
system("pause"); }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.35.160.209
→
11/14 19:32, , 1F
11/14 19:32, 1F
→
11/14 19:33, , 2F
11/14 19:33, 2F
→
11/14 19:33, , 3F
11/14 19:33, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章