 Quadractic Equation
 Bisection Method
int main()
{
float a,b,c,D,x,y;
clrscr();
printf(“Enter the coefficient of x2, coefficient of x and constant”);
scanf(“%f%f”,&a, &b, &c);
D=(b*b)-(4*a*c);
if(D<0)
{
printf(“Roots are Imagenary”);
}
if(D==0)
{
printf(“Both Roots are Same”);
x =(-b)/(2*a);
printf(“%f”, x);
}
if(D>0)
{
printf(“Both Roots are Real and Distinct:”);
x= (-b) + sqrt(D)/2*a;
y= (-b) - sqrt(D)/2*a;
printf(“%f%f”, x,y);
}
getch();
return 0;
}
#include<stdio.h>
#define e 0.001
#define f(x) x*x*x -4*x +1
void main()
{
float x0,x1,x2;
float f0,f1,f2;
clrscr();
printf(“Enter the values of x0 and x1”);
scanf(“%f%f”,&x0,&x1);
do{
f0 = f(x0);
f1 = f(x1);
x2=(x0+x1)/2;
f2=f(x2);
if(f0*f2<0)
{
x1=x2;
}
else
{
x0=x2;
}
i++;
printf(“No. of Iterations:=%d”,i);
printf(“Root:=%f”,x2);
printf(“Value of function =%fn”,f2);
}while(fabs(f2)<e);
getch();
Computer lab (programs)
Computer lab (programs)
Computer lab (programs)

Computer lab (programs)

  • 2.
  • 3.
    int main() { float a,b,c,D,x,y; clrscr(); printf(“Enterthe coefficient of x2, coefficient of x and constant”); scanf(“%f%f”,&a, &b, &c); D=(b*b)-(4*a*c); if(D<0) { printf(“Roots are Imagenary”); } if(D==0) { printf(“Both Roots are Same”); x =(-b)/(2*a); printf(“%f”, x); } if(D>0) { printf(“Both Roots are Real and Distinct:”); x= (-b) + sqrt(D)/2*a; y= (-b) - sqrt(D)/2*a; printf(“%f%f”, x,y); } getch(); return 0; }
  • 4.
    #include<stdio.h> #define e 0.001 #definef(x) x*x*x -4*x +1 void main() { float x0,x1,x2; float f0,f1,f2; clrscr(); printf(“Enter the values of x0 and x1”); scanf(“%f%f”,&x0,&x1); do{ f0 = f(x0); f1 = f(x1); x2=(x0+x1)/2; f2=f(x2); if(f0*f2<0) { x1=x2; } else { x0=x2; } i++; printf(“No. of Iterations:=%d”,i); printf(“Root:=%f”,x2); printf(“Value of function =%fn”,f2); }while(fabs(f2)<e); getch();