[ create a new paste ] login | about

Link: http://codepad.org/CMgOEoeA    [ raw code | output | fork ]

C++, pasted on Nov 6:
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main ()
{
	double k=0;
	double a=0;
	double e=0.001;
 
	double sum = 0;
	do
    {
		sum = sum + a;
		k = k + 1;
        a = (cos(k*k)*sin((2*k)-1) + 4.29)/k;
	}
	while(e < fabs(a));
	cout<<"Sum : "<<sum<<endl;
	cout<<"Num of interations : "<<setprecision(0)<<k<<endl;
	return 0;
}


Output:
1
2
Sum : 37.8508
Num of interations : 3e+03


Create a new paste based on this one


Comments: