C中浮点数的平方
发布时间:2020-12-16 10:20:51 所属栏目:百科 来源:网络整理
导读:我已经在C中编写了一个适用于int的代码,但是当我尝试使用float时,它显示错误我该怎么做才能使它正确. #includestdio.hint main(){ float a,y; float square(); scanf("%f",a); y = square( a ); printf("%f %f ",a,y);}float square(float b){ float z; z =
我已经在C中编写了一个适用于int的代码,但是当我尝试使用float时,它显示错误我该怎么做才能使它正确.
#include<stdio.h> int main() { float a,y; float square(); scanf("%f",&a); y = square( a ); printf("%f %f ",a,y); } float square(float b) { float z; z = b*b; printf("%f %f",z,b); return(z); } 错误: return.c:12: error: conflicting types for 'square' return.c:13: note: an argument type that has a default promotion can't match an empty parameter name list declaration return.c:6: note: previous declaration of 'square' was here 解决方法
将square()的声明移出函数并确保原型匹配:
float square(float b); // Make sure this matches the definition. int main() { float a,y; scanf("%f",b); return(z); } 至于它为int“工作”的原因,你必须向我们展示你用于该案例的确切代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |