Write a C program to find the roots of a quadratic equation.
Program Code:
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,r1,r2,d;
printf("enter the values of equation:");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
printf("\n enter non zero values");
else
{
d=b*b-4*a*c;
if(d>=0)
{
r1=((-b+sqrt(d))/(2*a));
r2=((-b-sqrt(d))/(2*a));
printf("\n the roots are=\t%f\t%f",r1,r2);
}
else
printf("\n roots are imaginary");
}
}
Post A Comment:
0 comments: