Skip to content

Instantly share code, notes, and snippets.

@yask123
Created May 12, 2015 11:29
Show Gist options
  • Select an option

  • Save yask123/217a58275cc1082f468d to your computer and use it in GitHub Desktop.

Select an option

Save yask123/217a58275cc1082f468d to your computer and use it in GitHub Desktop.
# include <stdio.h>
# include <math.h>
double f(double x)
{
return ( exp(x*x) );
}
int main()
{
double l1=0;
double l2=2;
int i=0;
double h = (l1+l2)/10;
double x=l1;
double y=0;
double sum=0;
while(x <= l2)
{
y = f(x);
if (i==0 || i== 9)
{
sum +=y;
}
else
{
sum+=2*y;
}
i+=1;
x+=h;
}
sum =(double)h/2*sum;
printf("%lf",sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment