berikut adalah listing program C dengan metode trapezoide:
#include "stdio.h"
#include "math.h"
double f(double x)
{
return(pow (x,2));
}
double intf(double x)
{
return(pow (x,3)/3);
}
void main()
{
int i;
float x,h,b,a,N,sum,L,Le,error;
printf("batas bawah: ");
scanf("%f",&a);
printf("batas atas: ");
scanf("%f",&b);
printf("jumlah pembagi N: ");
scanf("%f",&N);
h=(b-a)/N;
sum=0;
for(i=0;i<=N;i++)
{
x=a+i*h;
if(x==0 || x==N)
{
sum=sum+f(x);
}
else
{
sum=sum+(2*f(x));
}
}
L=h*sum/2;
Le=intf(b)-intf(a);
error=fabs(L-Le);
printf("luas Trapezoide= %f\n",L);
printf("Luas kalkulus= %f\n",Le);
printf("error= %f\n",error);
}
Friday, April 19, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Comment Form: