LISTING PROGRAM
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define fungsi x*x-84
float f(float x)
{
return(fungsi);
}
main()
{
clrscr();
float a,b,c,tol;
int max_itr,i,status;
i=1;
status=1;
printf("Menentukan nilai akar dari pers y=x^2x-84 dg Metode Regula Falsi \n");
printf("\n");
printf("Masukkan nilai a : ");scanf("%f",&a);
printf("Masukkan nilai b : ");scanf("%f",&b);
printf("Masukkan nilai tol : ");scanf("%f",&tol);
printf("Iterasi maksimal : ");scanf("%i",&max_itr);
puts("\n");
printf(" No a c b f(a) f(c) f(b)\n");
puts("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
if (f(a)*f(b) < 0)
{
do
{
c=a-(f(a)*(b-a))/(f(b)-f(a));
printf("%3i %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",i,a,c,b,f(a),f(c),f(b));
if ( f(a)*f(c) == 0)
{
status=0;
}
else
{
if (f(a)*f(c) < 0)
b=c;
else
a=c;
if (tol > fabs(c))
status=0;
if (i >= max_itr )
status=0;
}
i++;
}while(status==1);
}
else
{
puts("Maaf, pilih nilai a dan b kembali. karena tidak mengandung akar");
getch();
}
puts("\n");
printf("Akar = %8.2f", c);
getch();
}
0Awesome Comments!