C程序输出返回0

C程序输出返回0,c,C,我的C程序显示输出0; 没有编译器错误,我可以看到我输入的号码 #include <stdio.h> int main() { double height; double width; double perimeter; double area; perimeter = 2.0 * (height+width); area = width * height; printf("Enter the height of rec

我的C程序显示输出0; 没有编译器错误,我可以看到我输入的号码

#include <stdio.h>

int main() {

    double height;
    double width;
    double perimeter;
    double area;

    perimeter = 2.0 * (height+width);
    area = width * height;

    printf("Enter the height of rectangle:");
    scanf("%lf",&height);
    printf("You entered: %.2lf as height \n",height);

    printf("Enter the width of rectangle:");
    scanf("%lf",&width);
    printf("You entered: %.2lf as width \n",width);


    printf("\nthe area of rectangle is: %.2lf",area);
    printf("\nthe perimeter of rectangle is: %.2lf",perimeter);
    return 0;
}
#包括
int main(){
双高;
双倍宽度;
双周长;
双区;
周长=2.0*(高度+宽度);
面积=宽度*高度;
printf(“输入矩形的高度:”);
扫描频率(“%lf”和高度);
printf(“您输入:%.2lf作为高度\n”,高度);
printf(“输入矩形的宽度:”);
扫描频率(“%lf”和宽度);
printf(“您输入了:%.2lf作为宽度\n”,宽度);
printf(“\n矩形的面积为:%.2lf”,面积);
printf(“\n矩形的周长为:%.2lf”,周长);
返回0;
}

输出始终为0

在初始化它们使用的变量之前,计算周长和面积的值

因此,
scanf
s之后的这些行

周长=2.0*(高度+宽度);
面积=宽度*高度;

另外,请注意,未定义变量的值不一定是0。它可以是任何东西,如2,-42或546547981,因此使用这些变量之一的计算结果是未定义的(我们讨论)。

周长=2.0*(高度+宽度)在您读入这些值之后。同
面积=宽度*高度。该程序自上而下执行,因此您需要先读取值(
scanf
),然后才计算
周长
面积
。谢谢您,现在就收到了,这是一个很好的错误