Monday, 24 August 2015

Write a C Program To find the roots of an equation ax2 + bx + c = 0

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

int main()
{
            float a,b,c,alf,bt,dlt;
            clrscr();

            printf("\n Enter a: ");
            scanf("%f",&a);

            printf("\n Enter b: ");
            scanf("%f",&b);

            printf("\n Enter c: ");
            scanf("%f",&c);

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

            if(dlt==0)
            {
                        printf("\n ALPHA=BETA=%f",-b/(2*a));
            }
            else if(dlt<0)
            {
                        printf("\n Imaginary Roots");
            }
            else
            {
                        alf=(-b+sqrt(dlt))/(2*a);
                        bt=(-b-sqrt(dlt))/(2*a);
                        printf("\n\n Alpha = %f\n Beta=%f\n",alf,bt);
            }

            getch();

            return 0;

}

No comments:

Post a Comment