Skip to content

Instantly share code, notes, and snippets.

@synsh
Last active December 12, 2019 16:34
Show Gist options
  • Save synsh/34f97e2c28689d5b8cde8ce13f78fd9e to your computer and use it in GitHub Desktop.
Save synsh/34f97e2c28689d5b8cde8ce13f78fd9e to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<math.h>
float f(float x){
return (4*x-3*x*x);
/*
return (1/(1+x*x));
*/
}
int main(){
float a,b,n,h,sum1=0,sum2=0,sum,y0,yn;
int i;
printf("Enter the upper limit : ");
scanf("%f",&b);
printf("Enter the lower limit : ");
scanf("%f",&a);
printf("Enter the number of intervals : ");
scanf("%f",&n);
//step length
h=(b-a)/n;
y0=f(a+0*h);
yn=f(a+n*h);
for(i=1; i<n; i++)
sum1 = sum1 + f(a+i*h);
sum =(h/2)*(y0 + yn + 2*sum1);
printf("Answer : %.2f",sum);
getch();
return 0;
}
@ghosh7ananta
Copy link

Thank you brother

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment