GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


Simpson's Rule Stuff by Brendan
1
 
#include <stdio.h>
#include <math.h>


double f(double x);

void main()
{
    int n = 10;
    int a = 1;
    int b = 2;

    double h = (a-b)/(2*n);

    double sum = f(a);

    for(int j=1;j<(2*n);j++)
    {
        sum += (4-2*((j-1)%2))*f(1+(j*h)); 
    }

    sum += f(2*n);
    sum *= h/3;

    printf("%f\n",sum);
}

double f(double x)
{
    return (x*(exp(x)));
}


The errors I get are:
\program.c(17) : error C2143: syntax error : missing ';' before 'type'
\program.c(17) : error C2143: syntax error : missing ';' before 'type'
\program.c(17) : error C2143: syntax error : missing ', ')' before 'type'
\program.c(17) : error C2143: syntax error : missing ';' before 'type'
\program.c(17) : error C2065: 'j' : undeclared identifier
\program.c(17) : warning C4552: '<' : operator has no effect; expected operator with side-effect
\program.c(17) : error C2059: syntax error : ', ')'
\program.c(18) : error C2143: syntax error : missing ';' before '{'