Roots of a Qudratic Equation

Posted: February 12, 2010 in Basic Programming
Tags:

/* Program to find the roots of a quadratic equation */

#include<stdio.h>
#include<math.h>

main()
{
int a,b,c,descr;
double root1,root2,part;
printf(“\nEnter the co-efficients of a quadratic equation: “);
scanf(“%d%d%d”,&a,&b,&c);
descr=b*b-4*a*c;
if(descr<0)
printf(“\nThe roots are imaginary!!\n\n”);
else
{
if(descr==0)
printf(“\nThe roots are equal!\n\n”);
else
printf(“\nThe roots are unique!\n\n”);
part=sqrt((b*b)-(4*a*c));
root1=(-b+part)/(2*a);
root2=(-b-part)/(2*a);
printf(“\nThe roots are…..\nRoot1= %7.3f\nRoot2= %7.3f\n\n”,root1,root2);
}
}

Comments
  1. gouti says:

    Tat is very usefull

  2. gouti says:

    Tat is simple

Leave a comment