Monday 7 August 2017

code for checking roots

#include "stdio.h"
#include "conio.h"
#include "math.h"
float a,b,c,x1,x2,deter;
void main()
{
    printf("Enter The values of a\n");
    scanf("%f",&a);
    printf("Enter The values of b\n");
    scanf("%f",&b);
    printf("Enter The values of c\n");
    scanf("%f",&c);
    deter=b*b-4*a*c;
    if(deter>0)
    {
        printf("Roots are real\n");
        x1=(-b+sqrt(deter))/(2*a);
        x2=(-b-sqrt(deter))/(2*a);
        printf("X1 :%f and X2 :%f",x1,x2);
    }
    else if(deter<0)
        printf("Roots are imaginary\n");
    else if(deter==0)
    {
        printf("Roots are equal\n");
        x1=x2=-b/(2*a);
        printf("X1 :%f and X2 :%f",x1,x2);
    }
    getch();

0 comments: