if或者else多句的話儘量加{}你看看這樣行不行#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ long double a, b, c, x1, x2, delta1; printf("ax ^ 2 + b ^ x + c = 0\nplease input a, b, and c\n"); printf("a="); scanf("%f", &a); printf("b="); scanf("%f", &b); printf("c="); scanf("%f", &c); delta1 = b * b - 4 * a*c; printf("a=%fb=%fc=%f", a, b, c); { if (delta1 >= 0) { x1 = (-b + sqrt(b*b - 4 * a*c)) / (2 * a); x2 = (-b - sqrt(b*b - 4 * a*c)) / (2 * a); printf("x1=%f,x2=%f", x1, x2); } else { x1 = -b / (2 * a); x2 = sqrt(4 * a*c - b * b); printf("x1=%f+%fi,x2=%f-%fi", x1, x2, x1, x2); } return 0; }}
if或者else多句的話儘量加{}你看看這樣行不行#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ long double a, b, c, x1, x2, delta1; printf("ax ^ 2 + b ^ x + c = 0\nplease input a, b, and c\n"); printf("a="); scanf("%f", &a); printf("b="); scanf("%f", &b); printf("c="); scanf("%f", &c); delta1 = b * b - 4 * a*c; printf("a=%fb=%fc=%f", a, b, c); { if (delta1 >= 0) { x1 = (-b + sqrt(b*b - 4 * a*c)) / (2 * a); x2 = (-b - sqrt(b*b - 4 * a*c)) / (2 * a); printf("x1=%f,x2=%f", x1, x2); } else { x1 = -b / (2 * a); x2 = sqrt(4 * a*c - b * b); printf("x1=%f+%fi,x2=%f-%fi", x1, x2, x1, x2); } return 0; }}