Write the program to find the roots of quadratic

equations.

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main( )

{

int a,b,c,d;

float x,y;

printf(“Enter a,b,c”);

scanf(“%d %d %d”, &a, &b, &c);

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

if(d = = 0)

{

x = -b/2*a;

printf(“Roots are same %.3f %.3f”, x, x);

}

else

{

if(d>0)

{

x = (-b+sqrt(d))/(2*a);

y = (-b-sqrt(d))/(2*a);

printf(“Roots are real %.3f %.3f”,x ,y);

}

else

printf(“Roots are imaginary”);

}

getch( );

}

Output:-

Enter a, b, c 5, 7, 8

Roots are imaginary 1.053565

## Nov 17, 2010

Subscribe to:
Post Comments (Atom)

## 0 comments:

## Post a Comment