Thursday 25 August 2016

To find the roots of an equation

#include<stdio.h>
#include<math.h>
void main()
{
   
    int a,b,c;
    float d,x,y;
    printf("enter the value of a,b,c");
    scanf("%d%d%d",&a,&b,&c);
    d=(b*b)-(4*a*c);
    if(d>0){
     printf("roots are real and distinct");
     x=(-b+(sqrt(d)))/2*a;
     y=(-b-(sqrt(d)))/2*a;
     printf("roots are %f %f",x,y);
    }
    else if(d=0)
    {
        printf("roots are real and same");
        x=-b/(2*a);
        y=-b/(2*a);
        printf("roots are %f %f",x,y);
    }
    else
    {
        printf("roots are imaginary");
    }
}



No comments:

Post a Comment