Skip to content

Instantly share code, notes, and snippets.

@0V
Created April 17, 2015 08:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 0V/4b915d0e8cf91dd74587 to your computer and use it in GitHub Desktop.
Wallis' Formula by C++
// 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