-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroots.c
More file actions
39 lines (26 loc) · 738 Bytes
/
roots.c
File metadata and controls
39 lines (26 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <math.h>
main()
{
float a, b, c;
float discriminant;
float root1, root2;
float value_p;
printf("Computing roots of a*x^2 + b*x + c\n");
printf("Enter the coefficients a, b and c: ");
scanf("%f %f %f", &a, &b , &c);
discriminant = b*b - 4*a*c;
root1 = (-b + sqrt(discriminant))/(2*a);
root2 = (-b - sqrt(discriminant))/(2*a);
printf("First Root: %.3f\tSecond Root: %.3f\n", root1, root2);
value_p = 0;
value_p = a*root1*root1;
value_p += b*root1;
value_p += c;
printf("P(%f) = %f\n", root1, value_p);
value_p = 0;
value_p = a*root2*root2;
value_p += b*root2;
value_p += c;
printf("P(%f) = %f\n", root2, value_p);
}