Write a program to perform the bisection method in C. Create the following macro
ID: 3694064 • Letter: W
Question
Write a program to perform the bisection method in C. Create the following macro definitions MAX_ITERATIONS 100 ROWS MAX_ITERATIONS COLS 3 EPS 1e-6 Create a structure typedef above the main function called VALUES where 1st field is a two dimensional array names x of type double and size ROWS and COLS where ROWS is 100 and COLS is 3 both defined by a macro. 2nd field is an integer called rows 3rd field is an integer called columns 4th field is a double called root (initialize to zero) the following code is used within the main function to initialize the values values = {{0}, ROWS, COLS, 0};Explanation / Answer
#include<stdio.h>
#include <math.h>
#include<conio.h>
#define edrd 0.001
#define f(cc) (x)*(x)*(x) + (x)*(x) + (x) + 7
//main function.
void main()
{
int i = 1;
float cc0,cc1,cc2;
double f1,f2,f0,t;
printf(" Enter the value of cc0: ");
scanf("%f",&cc0);
printf(" Enter the value of cc1: ");
scanf("%f",&cc1);
//loop to find function of the expression.
do
{
cc2=(cc0+cc1)/2;
f0=f(cc0);
f1=f(cc1);
f2=f(cc2);
printf(" %d %f %f %f %lf %lf %lf", i, cc0,cc1,cc2,f0,f1,f2);
if(f0*f2<0)
{
cc1=cc2;
}
else
{
cc0=cc2;
}
i++;
}while(fabs(f2)>edrd);
printf(" value is ",cc2);
getch();
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.