fork download
  1. #include <stdio.h>
  2. int factorial(int n) {
  3. int f = 1;
  4. for (int i=1; i<=n; i++)
  5. f *= i;
  6. return f;
  7. }
  8. int main(){
  9. int n;
  10. long double result=0;
  11. for(n=0; n<=5; n++){
  12. if(n%2==0){
  13. result+=(((long double) 1/(long double)(factorial(n)*(2*n+1))));
  14. } else {
  15. result-=(((long double) 1/(long double)(factorial(n)*(2*n+1))));
  16. }
  17. }
  18. printf("The Gaussian integral from 0 to 1 is %Lf\n", result);
  19. }
  20.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
The Gaussian integral from 0 to 1 is 0.746729