Last active
December 12, 2019 16:34
-
-
Save synsh/34f97e2c28689d5b8cde8ce13f78fd9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you brother