-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare.cpp
77 lines (63 loc) · 1.52 KB
/
square.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <math.h>
int reshator(double a, double b, double c, double* x1, double* x2, int* solvenum)
{
double discriminant = b*b - 4*a*c;
if (a != 0)
{
if (discriminant >= 0)
{
if (discriminant == 0)
{
*x1 = (-b)/(2*a);
*x2 = (-b)/(2*a);
*solvenum = 1;
}
else
{
*x1 = (-b + sqrt(discriminant))/(2*a);
*x2 = (-b - sqrt(discriminant))/(2*a);
*solvenum = 2;
}
}
else
{
*solvenum = 0;
}
}
else
{
if (b != 0)
{
*x1 = (-c/b);
*x2 = (-c/b);
*solvenum = 1;
}
else
{
*solvenum = 0;
}
}
}
int main()
{
printf ("enter a,b,c (ax^2+bx+c)\n");
double a, b, c, x1, x2;
int solvenum;
scanf ("%lg", &a);
scanf ("%lg", &b);
scanf ("%lg", &c);
reshator(a, b, c, &x1, &x2, &solvenum);
if (solvenum==1)
{
printf("only solution: x = %lg", x1 );
}
if (solvenum==2)
{
printf("first soultion: x1 = %lg\nsecond solution: x2 = %lg", x1, x2);
}
if (solvenum==0)
{
printf("no solution");
}
}