/**
* Author : Berk Soysal
*/
#include <stdio.h>
#include <math.h> /* This is needed to use sqrt() function.*/
void main()
{
float a, b, c, delta, r1,r2, real, imag;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f",&a,&b,&c);
if(a ==0 || b==0)
{
printf("\n\nPlease enter nonzero values !\n");
}
else
{
delta=b*b-4*a*c;
if (delta>0)
{
r1= (-b+sqrt(delta))/(2*a);
r2= (-b-sqrt(delta))/(2*a);
printf("\n\nRoots are: %.2f and %.2f\n\n",r1 , r2);
}
else if (delta==0)
{
r1 = r2 = -b/(2*a);
printf("\n\nRoots are: %.2f and %.2f\n\n", r1, r2);
}
else
{
real= -b/(2*a);
imag = sqrt(-delta)/(2*a);
printf("\n\nRoots are: %.2f + %.2fi and %.2f - %.2fi\n\n", real, imag, real, imag);
}
}
}
Keywords: CCode Snippets
Disqus Comments Loading..