Tuesday, 4 October 2011

Program to find roots of quadratic equation


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,c,b;
float d,r1,r2;
clrscr();

printf("\n Enter values of coefficient of x^2, x , and constant : \n");
scanf ( "%d%d%d" ,&a,&b,&c);

d = sqrt((b*b) - (4*a*c));

r1= (-b+d)/(2*a);
r2= (-b-d)/(2*a);

printf("\n Roots are : %f and %f ",  r1, r2);
getch();
}

No comments:

Post a Comment