Program to find the roots of a quadratic equation.
Program to find the roots of a quadratic equation.
1 |
/*program to find the roots of a quardatic equation*/ |
2 |
#include <stdio.h> |
3 |
#include <math.h> |
4 |
#include <conio.h> |
5 |
|
6 |
/*Function to calculate the roots of quardatic*/ |
7 |
void quadaratic_root(int a,int b,int c) |
8 |
{ |
9 |
double x,y; |
10 |
printf("\n"); |
11 |
x=(-b+(pow(pow(b,2)-4*a*c,.5)))/(2*a); |
12 |
y=(-b-(pow(pow(b,2)-4*a*c,.5)))/(2*a); |
13 |
|
14 |
printf("%lf and %lf",x,y); |
15 |
} |
16 |
void main() |
17 |
{ |
18 |
int a,b,c; |
19 |
printf("Enter value for a: "); |
20 |
scanf("%d",&a); |
21 |
|
22 |
printf("Enter value for b: "); |
23 |
scanf("%d",&b); |
24 |
|
25 |
printf("Enter value for c: "); |
26 |
scanf("%d",&c); |
27 |
|
28 |
if(pow(b,2)-4*a*c<0) |
29 |
{ |
30 |
printf("Roots can't be find"); |
31 |
} |
32 |
else if(pow(b,2)-4*a*c==0) |
33 |
{ |
34 |
printf("Single Root"); |
35 |
quadaratic_root(a,b,c); |
36 |
} |
37 |
else if(pow(b,2)-4*a*c>0) |
38 |
{ |
39 |
printf("Double Root"); |
40 |
quadaratic_root(a,b,c); |
41 |
} |
42 |
getch(); |
43 |
} |