How to calculate PI value with atan() function in C++

2 Answers

0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double pi = atan(1) * 4;

	cout << "pi = " << pi << endl;

	return 0;
}

/*
run:

pi = 3.14159

*/

 



answered Apr 1, 2016 by avibootz
0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double pi = 2 * atan(INFINITY);

	cout << "pi = " << pi << endl;

	return 0;
}

/*
run:

pi = 3.14159

*/

 



answered Apr 2, 2016 by avibootz

Related questions

2 answers 437 views
2 answers 332 views
2 answers 409 views
2 answers 400 views
2 answers 447 views
2 answers 414 views
2 answers 491 views
...