19.(C) #Tricky Question--->>>> Finding the roots of ax^2+bx+c

 #include<stdio.h>

#include<math.h>
int main(){

    double a,b,c,x1,x2,discriminant,realpart,imgpart;
    printf("Enter \n a\n b\n c\n");
    scanf("%lf%lf%lf",&a,&b,&c);

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

    if(discriminant>0) // discriminant is used to identify the roots type
    {
       x1=(-b + sqrt(discriminant)) / (2 * a);
       x2=(-b - sqrt(discriminant)) / (2 * a);  /*we have to use
       -,+,*,/ with spaces for getting correct output*/

        printf("ax^2+bx+c solve =%lf and %lf\n",x1,x2);
    }

    else if(discriminant==0)
    {
        x1=x2=-b/(2*a);
        printf("ax^2+bx+c solve = %lf and %lf\n",x1,x2);
    }

    else

    {
        realpart=-b / (2 * a);
        imgpart=(sqrt(-discriminant)) / (2 * a);
        printf("ax^2+bx+c solve =%.2lf+%.2lf i and %.2lf-%.2lf i \n",realpart,imgpart,realpart,imgpart);

    }


    return 0;
}
// this program has teach me so many thing ,thanks mahedi hasan my frnd

Comments