Объяснение:
#include <iostream>
#include <cstdlib>
#include <cmath>
long double fact( const unsigned int a ) {
long double temp = 1;
for ( unsigned int i = 2; i <= a; i++ )
temp *= i;
return temp;
}
double fSinX( const double x, const unsigned int precision ) {
double tmp = 0;
for ( unsigned int n = 0; n < precision; n++ )
tmp += ( std::pow( -1., n ) / fact( 2 * n + 1 )) * std::pow( x, 2 * n + 1 );
return tmp;
int main( int argc, char** argv ) {
std::cout << fSinX( 2, 500 ) << std::endl; //своя функция
std::cout << std::sin( 2 ) << std::endl; //библиотечная функция
std::cout << std::endl;
std::system( "pause" );
return 0;
Объяснение:
#include <iostream>
#include <cstdlib>
#include <cmath>
long double fact( const unsigned int a ) {
long double temp = 1;
for ( unsigned int i = 2; i <= a; i++ )
temp *= i;
return temp;
}
double fSinX( const double x, const unsigned int precision ) {
double tmp = 0;
for ( unsigned int n = 0; n < precision; n++ )
tmp += ( std::pow( -1., n ) / fact( 2 * n + 1 )) * std::pow( x, 2 * n + 1 );
return tmp;
}
int main( int argc, char** argv ) {
std::cout << fSinX( 2, 500 ) << std::endl; //своя функция
std::cout << std::sin( 2 ) << std::endl; //библиотечная функция
std::cout << std::endl;
std::system( "pause" );
return 0;
}