C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- takezoh
- まろ
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- @tyottyoworks
- ___shanon
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
21
1
2
3
4
5
using namespace std;6
7
int main() {8
int N, i, j, fact = 1, sign = 1;9
float x, y = 0;10
cout << "Enter N (number of iterations),x (angle value in rad): ";11
cin >> N >> x;12
for (i = 1;i <= N;i++) {13
fact = 1;14
for (j = 1;j <= i;j++) {15
fact *= j;16
}17
y += sign * (pow(x, 2 * i - 1)) / fact;18
sign *= -1;19
}20
cout << "sin(" << x << ") = " << y << " the real value should be " << sin(x);21
}$ g++ prog.cc -Wall -Wextra -std=c++98 -pedantic
Stdin
10 0.5Start
Enter N (number of iterations),x (angle value in rad): sin(0.5) = 0.442398 the real value should be 0.479426
0
Finish