键盘有多个浮点输入

cam*_*ndo 0 c input scanf floating

我正在从单个scanf输出中读取多个浮点数.

#include<stdio.h>
#include<math.h>
int main()
{ float a,b,c;
  float d,rot1,rot2;
  scanf("%f%f%f ", &a, &b, &c);
  d = sqrt(b*b - 4*a*c);
  rot1 = (-b-d)/(2*a);
  rot2 = (-b+d)/(2*a);
  printf("%f %f", rot1, rot2);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

它需要4个输入; 但是,我想只为变量a,b和c的地址提供3个输入.我不知道从哪个变量获取额外的输入.当我编写用于获取2变量输入的代码时,它需要3个输入.

ame*_*yCU 5

scanf("%f%f%f ", &a, &b, &c);
             ^
Run Code Online (Sandbox Code Playgroud)

之后删除这个额外的空间%f.

- 您应确保表达式中的值sqrt不会计算为负数.你可能想避免这种情况.