Monday, 22 February 2016

How to write a c program to find all the solutions of a quadratic equation

Any quadratic equation have three types of solutions. Generally you can find the real solutions in the regular life. If you want to find all the solutions of a quadratic equation, then it is easy. we can solve it in mathematics. Now here is the question how to check these all solutions using any programming language.


                     Here I am presenting "How to write a c program to find all the solutions of a quadratic equation". Before we can do it, what are three solutions and when they appear that is in what conditions.

                 Generally before finding solutions to a quadratic equation we need to check is discriminator. Now the three conditions we need to checking are

1. If  the discriminator of equation is grater than zero, then the equation has " real roots and these roots are        not equal".

2. If  the discriminator of equation is equal to zero, then the equation has " real roots and these roots are              equal ".

3.If  the discriminator of equation is less than zero, then the equation has " Imaginary roots".


             The above three are the all time all possible solutions for a quadratic equation  for any given values.

Here is the C program to find the roots of quadratic equation  and this checks all the above three conditions.


C program to find the roots of quadratic equation


main()

 {

 float a,b,c,disc,r1,r2;

 printf(" enter the values of a,b,c \n");

 scanf( " %f,%f,%f", &a,&b,&c);

 disc= b*b-4*a*c;

 if ( disc>0)

 {

  printf(" roots are real and unequal");

 r1=(-b+sqart(disc))/(2.0*a);

 r2=(-b-sqart(disc))/(2.0*a);

 printf(" the real and unequal roots are %f,%f",r1,r2);

 }

 else if(disc= = 0)

 {

 printf(" the roots are real and equal");

 r1= -b/(2.0*a);

 r1=r2;

 printf(" the real and equal roots are %f,%f",r1,r2);

 }

 else  

 {

 printf(" the roots are Imaginary ");

 disc= -disc;

 r1=sqart(disc)(2.0*a);

 r2= -b/(2.0*a);

 printf(" the Imaginary roots are %f,%f",r1,r2);

 }

 } 

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top