Wallis' Formula by C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for Visual Studio | |
#define _CRT_SECURE_NO_WARNINGS | |
#include <iostream> | |
long double wallis_formula(int); | |
int main() { | |
int input_count = 0; | |
/* | |
* C++ Style | |
*/ | |
std::cin >> input_count; | |
long double result = wallis_formula(input_count); | |
std::cout << result << std::endl; | |
/* | |
* C Style | |
* | |
scanf("%d",&input_count); | |
long double result = wallis_formula(input_count); | |
printf("%f",result); | |
*/ | |
} | |
long double wallis_formula(int count) | |
{ | |
long double pi = 1.0; | |
for (int i = 1; i < count; i++) | |
{ | |
long double num = 4.0 * i * i; | |
pi *= num / (num - 1); | |
} | |
return pi * 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment