Sunday, April 24, 2016

C program to find the roots of a quadratic equation

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,root1,root2,root3;
clrscr();
printf("If the quadratic equation is ax2+bx+c=0 , then..");
printf("\nEnter the value of 'a' here: ");
scanf("%f",&a);
printf("Enter the value of 'b' here: ");
scanf("%f",&b);
printf("Enter the value of 'c' here: ");
scanf("%f",&c);
d=(b*b)-(4*a*c);
if(d>0)
{
root1=(-b+(sqrt(d))/(2*a));
root2=(-b-(sqrt(d))/(2*a));
printf("The roots of the equation are %f and %f",root1,root2);
}
else if(d==0)
{
root3=(-b/(2*a));
printf("The root is %f ",root3);
}
else
{
printf("No root");
}
getch();
}

No comments:

Post a Comment