program to calculate roots of quadratic equation ax2+bx+c=0




#include
#include
#include
int main (void)
{
int a,b,c;
float d,e,f,g;
printf("please enter the values of a,b,c respectively as in equation ax2+bx+c\n");
scanf("%i%i%i",&a,&b,&c);
d=b*b-4*a*c;
if(d>0)
{
e=(-b+sqrt(d))/2*a;
f=(-b-sqrt(d))/2*a;
printf("roots are real and they are %f%f",e,f);
}
else if(d==0)
{
e=-b/2*a;
printf("roots are real and equal and is equal to %f",e);
}
else
{
g=-b/2*a;
e=sqrt(-d)/2*a;
f=-sqrt(-d)/2*a;
printf("root are complex and they are %f + i %f",g,e);
printf("%f +i %f",g,f);
}
getch();
return 0;
}




No comments:

Post a Comment