C语言简单
#include<stdio.h>#include<math.h>
int main()
{
double a,b,c,d,v1,v2;
scanf("%d %d %d",&a,&b,&c);
d = b*b - 4*a*c;
v1 = (-b + sqrt(d)) /2.0/a;
v2 = (-b - sqrt(d)) /2.0/a;
printf("v1=%lf v2=%lf\n",v1,v2);
return;
}
这里的为啥用double不行? 你定义a,b,c是double型的,输入也得用%lf,scanf("%lf%lf%lf",&a,&b,&c); double 是双精度浮点数,输入要用%lf
具体就是scanf("%lf%lf%lf",&a,&b,&c);{:10_256:} a327190489 发表于 2020-11-19 11:14
你定义a,b,c是double型的,输入也得用%lf,scanf("%lf%lf%lf",&a,&b,&c);
谢谢
页:
[1]