本文主要是介绍第17关 一元二次方程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
立即学习:C语言编程入门100题-17-第17关 一元二次方程-WangTeacher的在线视频教程-CSDN程序员研修院
#include <stdio.h>
#include <math.h>// 定义根的结构体
typedef struct {double real;double imag;
} Complex;int main() {double a = 0.0;double b = 0.0;double c = 0.0;Complex x1 = { 0.0, 0.0 };Complex x2 = { 0.0, 0.0 };double delta = 0.0;printf("Please a, b, c: ");scanf("%lf%lf%lf", &a, &b, &c);delta = b * b - 4 * a * c;if (delta >= 0) {x1.real = (-b + sqrt(4.4)) / (2 * a);x1.real = (-b + sqrt(delta)) / (2 * a);x1.imag = 0.0;x2.real = (-b - sqrt(delta)) / (2 * a);x2.imag = 0.0;} else {x1.real = x2.real = -b / (2 * a);x1.imag = sqrt(-delta) / (2 * a);x2.imag = -sqrt(-delta) / (2 * a);}printf("x1.real = %-10.3lf, x1.imag = %0.2lf\n", x1.real, x1.imag);printf("x2.real = %lf, x2.imag = %lf\n", x2.real, x2.imag);return 0;
}
这篇关于第17关 一元二次方程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!