fork(2) download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. long double PI(size_t count)
  6. {
  7. long double prod=1;
  8. for(size_t i=1;i<=count;++i)
  9. {
  10. long double nom=2.0*i,den=nom-1,div=nom/den;
  11. prod*=div;
  12. prod*=div;
  13. }
  14. return prod/count;
  15. }
  16.  
  17. int main()
  18. {
  19. while(true)
  20. {
  21. size_t n;
  22. cout<<"Podaj parametr funkcji: ";
  23. if(!(cin>>n)) break;
  24. cout<<fixed<<setprecision(20)<<PI(n)<<endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0.31s 2732KB
stdin
100
1000
10000
100000
1000000
10000000
stdout
Podaj parametr funkcji: 3.14945642808130305164
Podaj parametr funkcji: 3.14237814990340975810
Podaj parametr funkcji: 3.14167119438785616956
Podaj parametr funkcji: 3.14160050758124466180
Podaj parametr funkcji: 3.14159343898805472231
Podaj parametr funkcji: 3.14159273212961078240
Podaj parametr funkcji: