c program to find the roots of a quadratic equation
c program to find the roots of a quadratic equation using if else
here is c program witch is calculate the root of Quadric equation
find the roots of a Quadratic Equation#include<stdio.h>
int main()
{
float a,b,c,d,realp,imgp,r1,r2;
printf("Enter the 3 number \n");
scanf("%f %f %f",&a,&b,&c);
if(a==0|| b==0|| c==0)
{
printf("Error the input only non zero numbers\n");
}
else
{
d=b*b-4*a*c;
if(d==0)
{
printf("Rootre are Equal \n");
r1=r2=-b/(2*a);
printf("root 1=%f,root2=%f",r1,r2);
}
else if(d>0)
{
printf("roots are real & distinct\n ");
r1=(-b+sqrt(fabs(d)))/(2*a);
r2=(-b-sqrt(fabs(d)))/(2*a);
printf("root1=%f,root2=%f",r1,r2);
}
else
{
printf("Root are a imaginary \n");
realp=-b/(2*a);
imgp=sqrt(fabs(d))/(2*a);
printf("root1=%f+i%f,%f-i%f",realp,imgp,realp,imgp);
}
}
}
No comments:
Post a Comment