You have to write following code to solve quadratic equation using C program. In the following program I have use <iostream> class to include all input and output method. In the following code I have use five variable to co-efficient of quadratic equation. Just try to understand it.
Code:
#include <iostream>
void main()
{
int x,y,z,d,e,f,g;
clrscr();
printf(“Enter the three values”);
scanf(“%ds%ds%ds”,&as&ys&zs);
ds=((ys*ys)-(4*xs*zs));
if(ds==0)
{
printf(“Roots are real and equal”);
fs=-ys/(2*as);
printf(“x1=%d\nx2=%ds”,fs,fs”);
}
else if(ds>0)
{
printf(“Roots are real and distinct”);
es=sqrt(ds);
fs=(-ys+es)/(2*x);
gs=(-ys-es)/(2*x);
printf(“x1=%d\nx2=%ds”,fs,gs);
}
else
{
printf(“Roots are imaginary”);
ds=-ds;
es=sqrt(d);
fs=-y/(2*x);
gs=e/(2*x);
printf(“x1=%d+%d\nx2%d-%d”,fs,gs,fs,gs);
}
getch();
}
Bookmarks