C program to find roots of a quadratic equation

 


C program code to find roots of quadratic equation and the code is below 👇


#include <stdio.h>

#include <conio.h>

#include <math.h>

int main( )

{

    int a,b,c;

    float disc,root1,root2;

    float img,real;

    printf("Enter the values for a,b,c:\n");

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

    disc=(float)b*b-4*a*c;

    if(disc>0)

    {

        printf("The roots are real & unequal:\n");

        root1=( -b+sqrt(disc))/(2*a);

        root2=( -b-sqrt(disc))/(2*a);

        printf("root1=%f\n" , root1);

        printf("root2=%f\n" , root2);

    }

    else if(disc==0)

    {

        printf("The roots are real and equal:\n");

        root1=-b/(2*a);

        root2=root1;

        printf("root1=%f\n" , root1);

        printf("root2=%f\n" , root2);

    }

    else

    {

        printf("The roots are imaginary:\n");

        disc=-disc;

        img=(float)disc/2*a;

        real=(float)-b/2*a;

        if (img>0)

        {

            printf("root1=%f + i%f\n" ,real,img);

            printf("root2=%f - i%f\n" ,real,img);

        }

        else

        {

            img=-img;

            printf("root1=%f + i%f\n" ,real,img);

            printf("root2=%f - i%f\n" ,real,img);

        }

    }

    return 0;

}


If code is not working feel free to Contact us


cooltechyfacts

In this you can get tips&tricks 2-app reviews 3-tech news & facts 4-New mobile launch dates 5-facts about tech,life,and more facebook

Post a Comment

Previous Post Next Post

Contact Form