Wednesday, 23 April 2014

Write a program to find the roots of a quadratic equation



#include<stdio.h>
#include<conio.h> void main()
{
int a,b,c,d,e,f,g; clrscr();
printf("Enter the three values"); scanf("%d%d%d",&a,&b,&c);
d=((b*b)-(4*a*c)); if(d==0)
{
printf("Roots are real and equal\n"); f=-b/(2*a); printf("x1=%d\nx2=%d",f,f);
}
else if(d>0)
{
printf("Roots are real and distinct\n"); e=sqrt(d);
f=(-b+e)/(2*a);
g=(-b-e)/(2*a); printf("x1=%d\nx2=%d",f,g);
}
else
{
printf("Roots are imaginary\n"); d=-d;
e=sqrt(d); f=-b/(2*a);
g=e/(2*a);
printf("x1=%d+%d\nx2%d-%d",f,g,f,g);
}
getch();
}

No comments:

Post a Comment