啊哈磊_编程从这里起步

标题: 报错“else”without a previous"if" [打印本页]

作者: pompeii    时间: 2020-9-21 16:45
标题: 报错“else”without a previous"if"
  1. #   include <stdio.h>
  2. #   include <math.h>
  3. int main(void)
  4. {
  5.     //把三个系数保存到计算机中
  6.     int a=1;
  7.     int b=2;
  8.     int c=3;
  9.     double delta;
  10.     double x1;
  11.     double x2;
  12.     delta=b*b-4*a*c;
  13.     if (delta>0)
  14.     {
  15.         x1=(-b+sqrt(delta))/(2*a);
  16.         x2=(-b-sqrt(delta))/(2*a);
  17.         printf("该一元二次方程两个解,x1=%f,x2=%f",x1,x2);
  18.     }
  19.     else if (delta==0)
  20.     {
  21.         x1=(-b)/(2*a);
  22.         x2=x1;
  23.         printf("该方程有唯一解,x1=x2=%f",x1,x2);
  24.     }
  25.     else
  26.     {
  27.         printf("无解");
  28.     }
  29.     return 0;
  30. }
复制代码





欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2