1、scanf("%lf,%lf,%lf",&a,&b,&c);
输入数据时英文状态下的逗号隔开
2、scanf("%lf%lf%lf",&a,&b,&c);
输入数据时用空格隔开
一:代码:
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,d,x1,x2;
printf("请输入系数:\r\n");
scanf("%lf,%lf,%lf",&a,&b,&c);
printf("%lf,%lf,%lf\r\n",a,b,c);
d=sqrt(b*b-4*a*c);
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
if(x1<x2) printf("%.2lf,%.2lf\n",x1,x2);
else printf("%.2lf,%.2lf\n",x2,x1);
return 0;
}
//输入数字以英文输入状态下的逗号隔开
请输入系数:
1,-3,2
1.000000,-3.000000,2.000000
1.00,2.00
--------------------------------
Process exited after 11.21 seconds with return value 0
请按任意键继续. . .
//输入数字以中文输入状态下的逗号隔开
请输入系数:
1,-3,2
1.000000,0.000000,0.000000
-1.#J,-1.#J
--------------------------------
Process exited after 7.52 seconds with return value 0
请按任意键继续. . .
//输入数字以中或英文输入状态下的空格隔开
请输入系数:
1 -3 2
1.000000,0.000000,0.000000
-1.#J,-1.#J
--------------------------------
Process exited after 13.98 seconds with return value 0
请按任意键继续. . .
二:
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,d,x1,x2;
printf("请输入系数:\r\n");
scanf("%lf%lf%lf",&a,&b,&c);
printf("%lf,%lf,%lf\r\n",a,b,c);
d=sqrt(b*b-4*a*c);
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
if(x1<x2) printf("%.2lf,%.2lf\n",x1,x2);
else printf("%.2lf,%.2lf\n",x2,x1);
return 0;
}
//输入数字以中或英文输入状态下的空格隔开
请输入系数:
1 -3 2
1.000000,-3.000000,2.000000
1.00,2.00
--------------------------------
Process exited after 9.638 seconds with return value 0
请按任意键继续. . .
//输入数字以中或英文输入状态下的逗号隔开
请输入系数:
1,-3,2
1.000000,0.000000,0.000000
-1.#J,-1.#J
--------------------------------
Process exited after 8.285 seconds with return value 0
请按任意键继续. . .