#include "stdafx.h"
#include <iostream>
#include <cmath>
# define M_PIl 3.141592653589793238462643383279502884L
using namespace std;
long double fact(int N)
{
if (N < 0)
return 0;
if (N == 0)
return 1;
else
return N * fact(N - 1);
}
int main()
cout << " n = ";
int n; cin >> n;
cout << " h = ";
float h; cin >> h;
float x = 0; int i = 1; float S = 1;
if (n == 0)
cout << "S(" << x << ") = " << 0 << endl;
while ((x <= 1) && (i <= n))
S += (cos(i*(M_PIl / 4)) / fact(i))*pow(x, i);
cout << "S(" << x << ") = " << S << endl;
x = x + h;
i = i + 1;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include "stdafx.h"
#include <iostream>
#include <cmath>
# define M_PIl 3.141592653589793238462643383279502884L
using namespace std;
long double fact(int N)
{
if (N < 0)
return 0;
if (N == 0)
return 1;
else
return N * fact(N - 1);
}
int main()
{
cout << " n = ";
int n; cin >> n;
cout << " h = ";
float h; cin >> h;
float x = 0; int i = 1; float S = 1;
if (n == 0)
{
cout << "S(" << x << ") = " << 0 << endl;
}
else
{
while ((x <= 1) && (i <= n))
{
S += (cos(i*(M_PIl / 4)) / fact(i))*pow(x, i);
cout << "S(" << x << ") = " << S << endl;
x = x + h;
i = i + 1;
}
}
return 0;
}