![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhys1Ki0WLtr0Z07t_9jUZj2UtoGlVw-MMHZbUDSk8x1S2Ne3wylLvDVKXBtZaONHbt0VQk-uaDGveMw9mGeQncqCzPZDmjPt3q6wRGreSFVr78q0f5Otl4zPw_5Q5PVnLmnQGWh7XjsGc/s640/cc.jpg)
/**
* 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..