Wednesday, 25 March 2015

C program to find roots of a quadratic equation




This program will print the roots for a given quadratic equation



#include<stdio.h>
// linking with the math library
#include<math.h>

void main()

{

int a,b,c;
float sq,r1,r2;
clrscr();
printf("enter the values of a ,b and c of the quadratic equation ax^2+bx+c");
scanf("%d %d %d",&a,&b,&c);

//using standard lib math function

sq= sqrt((b*b)-(4*a*c));
r1= ((-b)+sq)/2*a;
r2= (b+sq)/2*a;
printf("Roots of the equation are %f %f",r1,r2);
getch();
}
        

0 comments:

Post a Comment