calculati in c++ x-x^3/3!+x^5/5!-...+(-1)^n*(x^(2n+1))/(2n+1)!
Răspunsuri la întrebare
Prima data citeste x,apoi n.
#include <iostream>
#include <cmath>
using namespace std;
long long factorial(int n)
{
long long p=1;
int i;
for(i=1;i<=n;i++)
p=p*i;
return p;
}
int main()
{
double x,s=0.0;
int n,i;
cin>>x>>n;
for(i=0;i<=n;i++)
if(i%2==0)
s+=(double)pow(x,2*i+1)/factorial(2*i+1);
else
s-=(double)pow(x,2*i+1)/factorial(2*i+1);
cout<<s;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
double factorial (int h)
{
if (h == 1 || h == 0) return 1;
return h * factorial (h-1);
}
int main()
{
double x, n, s = 0;
cin >> x >> n;
for (int i = 1; i < n; i++)
{
s = s + factorial(pow(x , (2*i+1)/(2*i+1)));
}
cout << s;
/*Nu am inteles perfect formula dar s-ar putea sa trebuiasca s = s + (-1*pow( x, factorial(pow(x , (2*i+1)/(2*i+1)))))
*/
return 0;
}