Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Created February 25, 2011 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaDogg/843763 to your computer and use it in GitHub Desktop.
Save JaDogg/843763 to your computer and use it in GitHub Desktop.
paper1b_1.cpp
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int m_upper;
double x,B = 0.0,den;
cout << "input m's upper limit :"; cin >> m_upper;
if (m_upper < 0)
{
cout << "m's upper limit cannot be smaller than 0" << endl;
return -1;
}
cout << "input x :"; cin >> x ;
for(int m = 0;m<= m_upper;m++)
{
den = 1.0;
for(int a = 1;a <= 2*m;a++)
{
den *= double(a);
}
B += pow(x,double(2*m)) / den;
}
cout << "B = ";
cout << setiosflags(ios::fixed) << setprecision(3);
cout << B;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment