c语言一元二次方程求解编程英语
The quadratic equation is a second-degree polynomial equation of the form ax^2 + bx + c = 0, where a, b, and c are real numbers and a ≠ 0.
The solutions to a quadratic equation can be found using the quadratic formula:c语言printf用法例子简单
x = (-b ± sqrt(b^2 4ac)) / 2a.
where sqrt() is the square root function.
Here is a C program that implements the quadratic formula to solve a quadratic equation:
c.
#include <stdio.h>。
#include <math.h>。
int main() {。
double a, b, c;
double discriminant, root1, root2;
printf("Enter the coefficients of the quadratic equation (a, b, and c): ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = bb 4ac;
if (discriminant > 0) {。
root1 = (-b + sqrt(discriminant)) / (2a);
root2 = (-b sqrt(discriminant)) / (2a);
printf("The roots of the quadratic equation are: %.2lf and %.2lf\n", root1, root2);
} else if (discriminant == 0) {。
root1 = root2 = -b / (2a);
printf("The quadratic equation has a single root: %.2lf\n", root1);
} else {。
printf("The quadratic equation has no real roots.\n");
}。
return 0;
}。
Here is an example of how to use the program:
Enter the coefficients of the quadratic equation (a, b, and c): 1 -4 5。
The roots of the quadratic equation are: 1.00 and 5.00。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论