我需要編寫一個程序來計算矩形的面積和周長。它必須使用該區域的功能,併爲周界使用第二個功能。使用函數的矩形長度和麪積程序
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