Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- long fact(int n) { //функция вычисления факториала
- if (n==0) return 1; //условие выхода из рекурсии
- else
- return n*fact(n-1); //начало рекурсии
- }
- int main() {
- int n;
- double y, s, sn;
- cout << "x y F(x) n"; //шапка таблицы
- for (float x=0;x<=1;x+=0.2) //перебор заданных х
- {
- y=cos(x);
- s=0; n=0;
- do { //цикл для вычисления S(x) с заданной погрешностью
- sn=pow(-1,n)*pow(x,2*n)/fact(2*n);
- s+=sn;
- n++;
- }
- while (abs(sn)>0.000001); //погрешность - условие выхода из цикла
- cout << endl << x << " " << y << " " << s << " " << n; //вывод таблицы
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement