Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int silnia (int n)
- {
- if (n == 0) return 1;
- else return n*silnia(n-1);
- }
- int main(){
- double x;
- cout << "Podaj x\n";
- cin >> x;
- double eps = 0.0001;
- double sum = 0.0;
- double prev = 0.0;
- int n = 0;
- while(fabs(sum - prev) > eps){
- prev = sum;
- sum += (pow(-1, n) / (silnia(2*n))) * pow(x, 2*n);
- n++;
- cout << sum << endl;
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement