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);
}
}

Advertisements
Comments
  1. gouti says:

    Tat is very usefull

  2. gouti says:

    Tat is simple

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s