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 439 views
2 answers 334 views
2 answers 410 views
2 answers 402 views
2 answers 449 views
2 answers 417 views
2 answers 494 views
...