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 288 views
2 answers 198 views
2 answers 257 views
2 answers 260 views
2 answers 251 views
2 answers 288 views
2 answers 343 views
...