Write a C Program to find the roots of quadratic equation

By | 02.11.2016

Find Roots of quadratic equation


Write a C Program to find the roots of quadratic equation. Here’s simple Program to find the roots of quadratic equation in C Programming Language.


Nature of roots of quadratic equation can be known from the quadrant = b24ac

  • If b24ac >0 then roots are real and unequal
  • If b24ac =0 then roots are real and equal
  • If b24ac <0 then roots are imaginary

Below is the source code for C Program to find the roots of quadratic equation which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


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

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

int main()
{
    int A, B, C;
    float disc, deno, x1, x2;
    printf("ENTER THE VALUE OF A :: ");
    scanf("%d", &A);
    printf("\nENTER THE VALUE OF B :: ");
    scanf("%d",&B);
    printf("\nENTER THE VALUE OF C :: ");
    scanf("%d",&C);

    disc=(B*B)-(4*A*C);
    deno = 2 * A;
    if(disc > 0)
    {
    printf("\nTHE ROOTS ARE REAL ROOTS.");
    x1 = (-B/deno)+(sqrt(disc)/deno);
    x2 = (-B/deno)-(sqrt(disc)/deno);
    printf("\n\nTHE ROOTS ARE :: %f and %f\n", x1, x2);
    }
    else if(disc == 0)
    {
    printf("\nTHE ROOTS ARE REPEATED ROOTS.");
    x1 = -B/deno;
    printf("\n\nTHE ROOT IS :: %f\n", x1);
    }
    else
    printf("\nTHE ROOTS ARE IMAGINARY ROOTS.\n");

    return 0;
}

OUTPUT : :


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

***************** OUTPUT *************

ENTER THE VALUE OF A :: 1

ENTER THE VALUE OF B :: 6

ENTER THE VALUE OF C :: 8

THE ROOTS ARE REAL ROOTS.

THE ROOTS ARE :: -2.000000 and -4.000000

Above is the source code for C Program to find the roots of quadratic equation which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

5 1 vote
Article Rating
Category: Basic Programs C Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments