Search This Blog

Friday, April 22, 2011

CODE 03

//GAURAV MITTAL(2K9/EE/830)
//QUESTION 3. Find the solution of a given Quadratic Equation.

#include
#include
#include

int main ()
{
float a,b,c;

printf("Let the eqation be ax^2 + bx + c");
printf("\nEnter a : ");
scanf("%f",&a);
printf("\nEnter b : ");
scanf("%f",&b);
printf("\nEnter c : ");
scanf("%f",&c);

float d;
d=b*b-4*a*c;

float x,y;

if((d>0)||(d==0))
{
printf("\nThe roots are real : ");
x=(((-1)*b+sqrt(d))/(2*a));
printf("\n");
printf("%f",x);
y=(((-1)*b-sqrt(d))/(2*a));
printf("\n");
printf("%f",y);
}
else
{
printf("\nThe roots are not real : ");
d=sqrt((-1)*d);
x=(((-1)*b)/(2*a));
printf("\n");
printf("%f",x);
printf(" + ");
printf("i");
printf("%f",d);

y=(((-1)*b)/(2*a));
printf("\n");
printf("%f",x);
printf(" - ");
printf("i");
printf("%f",d);


}
getch();
return 0;
}

No comments:

Post a Comment