大佬求解!,為什么我輸long是1.1,wide是1.1,結(jié)果出來(lái)一大串不知所云的數(shù)字。根本不是結(jié)果
#include<math.h>
double area(double a,double b)
{double s=a*b;
return s;}
#include<stdio.h>
main(){
double a, b ,s;
printf("how much is your long");
scanf("%f",&a);
printf("how much is your wide");
scanf("%f",&b);
s=area(a,b);
printf("%f",s);
}
2018-11-26
double 類(lèi)型使用%f格式會(huì)導(dǎo)致輸入值錯(cuò)誤,換成%lf就可以了。
#include<stdio.h>
#include<math.h>
double area(double a,double b){
double s=a*b;
return s;
}
int main(){
double a, b ,s;
printf("how much is your long");
scanf("%lf",&a);
printf("how much is your wide");
scanf("%lf",&b);
s=area(a,b);
printf("%lf",s);
return 0;
}