我需要编写一个程序来计算矩形的面积和周长。它必须使用该区域的功能,并为周界使用第二个功能。使用函数的矩形长度和面积程序
perimeter = 2 x length + 2 x width = 2l + 2w
area = legnth x width = l x w
到目前为止,我的代码是这样的:
#include <stdio.h>
double perimeter(double x);
double area(double w);
int main(){
double x, w;
printf("Enter the length: ");
scanf("%lf", &x);
prntf("Enter the width: ");
scanf("%lf", &w)
printf("The perimeter is %lf\n", perimeter);
printf("The area is %lf\n", area);
return 0;
}
double perimeter(double x, w){
return (2*x)+(2*w);
}
double area(double x, w){
return (x*w);
}
我收到以下错误:
(17): error C2146: syntax error: missing ';' before identifier 'printf'
(17): warning C4477: 'printf' : format string '%lf" requires an argument of type 'double', but variadic argument 1 has type 'double (___cdecl *)(double)'
(18): warning C4477: 'printf' : format string '%lf" requires an argument of type 'double', but variadic argument 1 has type 'double (___cdecl *)(double)''
(21): error C2081: 'w': name in formal parameter list illegal
(21): warning C4029: declared formal parameter list different from definition
(24): error C2081: 'w': name in formal parameter list illegal
(24): warning C4029: declared formal parameter list different from definition
谢谢你,拿了一堆错误的照顾。 (17)警告C4477:'printf':格式化字符串'%lf'需要和'double'类型的参数,但可变参数1的类型是double(___cdecl *)(double,double)' – Thad
我明白了。 – Thad