to find the roots of a quadratic equation

Every Quadratic equation has two roots. And this program is implemented to find the roots of the entered quadratic equation.

Logic : The roots of any quadratic equation of the the form, are,

The same equation is computerized here. The program asks user to enter the three coefficients a, b and c. Then it finds out numerator- which is the discriminate,  and the denominator of the equation of the roots. Then it checks if the numerator is greater, equals or less than zero. Prints out the results according to the situation.

This can be elaborated to find the roots of equation with higher powers. You are pleased to contact us with your doubts through the discussion forum.

#include<stdio.h>
#include<math.h>
void main()
{
int A, B, C;
float disc, deno, x1, x2;
clrscr();
printf(“\n\n\t ENTER THE VALUES OF A,B,C…”);
scanf(“%d,%d,%d”, &A, &B, &C);
disc = (B * B) – (4 * A * C);
deno = 2 * A;
if(disc > 0)
{
printf(“\n\t THE ROOTS ARE REAL ROOTS”);
x1 = (-B/deno) + (sqrt(disc) / deno);
x2 = (-B/deno) – (sqrt(disc) / deno);
printf(“\n\n\t THE ROOTS ARE…: %f and %f\n”, x1, x2);
}
else if(disc == 0)
{
printf(“\n\t THE ROOTS ARE REPEATED ROOTS”);
x1 = -B/deno;
printf(“\n\n\t THE ROOT IS…: %f\n”, x1);
}
else
printf(“\n\t THE ROOTS ARE IMAGINARY ROOTS\n”);
getch();
}

Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

One thought on “to find the roots of a quadratic equation

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in