#include<stdio.h>

#include<conio.h>

#include<math.h>

void main(void)

{

clrscr();

float a,b,c;

float d,e,y,z,p,x1,x2;

printf("\nEnter tha value of a:");

scanf("%d",&a);

printf("\nEnter tha value of b:");

scanf("%d",&b);

printf("\nEnter tha value of c:");

scanf("%d",&c);

d=pow(b,2);

e=2*a;

y=4*a*c;

z=d-y;

p=sqrt(z);

x1=(-b+p)/(e);

x2=(-b-p)/(e);

printf("\n First root of quadratic equation=%f",x1);

printf("\n Second root of quadratic equation=%f",x2);

getch();

}

Enter tha value of a:2 Enter tha value of b:5 Enter tha value of c:3 First root of quadratic equation=-1.250000 Second root of quadratic equation=-1.250000

It compiles and runs for me. Have you tried a complier updated since you were born?

But you can easily pick values of a, b, and c that would give that error (1, 0, 1 for example). You really need to check that z is not negative; otherwise there are no real solutions to the equation. A good program would solve all cases by producing complex answers too.

Ask Your Question

Weekly Poll

Would you ride in a self-driving car from Tesla?

Discuss in The Lounge

Poll History