Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Решение квадратного уравнения.
- // Solving a quadratic equation.
- #include <stdio.h>
- #include <math.h>
- float a,
- b,
- c,
- x1,
- x2,
- D, // discriminant
- res; // sqrt of discriminant
- ////////////////////////////////////////////////////
- int main() //
- {
- printf("a = "); scanf("%f", &a);
- printf("b = "); scanf("%f", &b);
- printf("c = "); scanf("%f", &c);
- D = (b*b) - (4*a*c);
- if(D < 0) {
- printf("\nDiscriminant < 0, no root.");
- return 0;
- }
- res = sqrt(D);
- if(D > 0) {
- x1 = (-b + res)/(2 * a);
- x2 = (-b - res)/(2 * a);
- printf("\nDiscriminant > 0 (2 root's): \n");
- printf("x1 = %6.2f \n", x1);
- printf("x2 = %6.2f \n", x2); return 0;
- }
- x1 = (-b)/(2 * a);
- printf("\nDiscriminant = 0, only one solution. \n");
- printf("x = %.2f", x1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement