Sunday, 20 October 2013

C-Program to Find Roots of a Quadratic Equation

#include<stdio.h>
#include<math.h>
main ()
{
int a,b,c,x1,x2,d;
printf("Enter the values of coeficients\t");
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-4*a*c;
if(d>=0)
{
x1=((-b)+sqrt(d))/2*a;
x2=((-b)-sqrt(d))/2*a;          
if(x1==x2)
printf("Same roots which is \t%d \n",x1);
else
printf("Distinct roots which are \t%d %d \n",x1,x2);
}
else
printf("Imaginary Roots\n");
}



sakoncepts.blogspot.com
output



No comments:

Post a Comment