Q:

Write a C Program to find the roots of quadratic equation

0

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 = b2−4ac

  • If b2−4ac >0 then roots are real and unequal
  • If b2−4ac =0 then roots are real and equal
  • If b2−4ac <0 then roots are imaginary

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Basic Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to find area and circumference o... >>
<< Write a C Program to find the gross salary and net...