All pastes #929967 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-06 04:57 UTC
rendered paste body
#include <stdio.h>
#include <math.h>
#define PI 3.1415927

long int factorial(int n)
{
    long int fact = 1;
    int i;
    for (i = 2; i <= n; i++) {
        fact = fact * i;
    }
    return fact;
 }

int main (void)
{
        int i;
        float input;
 
        printf("Enter a number: ");
        scanf("%f",&input);
        
        double solution = 0;
        double term;
        
        for (i = 0; i < 20; i++) {
            term =  pow(input,2*i+1) / (2*i+1) / factorial(i);
            if (i % 2 != 0) { 
               term = term * -1;
            }
            
            solution = solution + term;
        }  
        
        solution = solution * 2/(sqrt(PI));     
        printf("Solution = %f \n", solution);        
        return 0;
}