L 23

You might also like

You are on page 1of 2

#include <stdio.

h>
#include <stdlib.h>
#include <math.h>
double trapezoid(double a,double b,double h)
{
int S;
S = (a + b)*h;
return(S);
}
double f(double x)
{
double y;
y = - (x*x) + 4x ;
return(y);
}
main()
{
int i, k, N;
double a, b, h, ds, S, dx;
printf("y=-(x^2)+x S \n");
printf("");
scanf("%f\n",&N);
double x[N], y[N] ,dr[N-2];
S = 0;
dx = 4/N;
/*k = i + 1;*/
for(k = 1 ;k<=(N-1) ;k++ )
{
x[k] = (k*dx);
y[k] = f(x[k]);
}
for(i=1 ;i<=(N-2) ;i++ )
{
dr[i] = sprt( (x[i])*(x[i]) + ((y[i+1])-(y[i])) );
if(dr[i]<0)
{

dr[i] = dr[i]*(-1);
}
ds[i] = trapezoid(dx,dr[i],y[i]);
S = S + ds[i];
}
S = S + dx*y[1]*(1/2);
S = S + dx*y[N-1]*(1/2);
printf("%f",S);
return(0);
}
/**/

You might also like