这是我在C代码,我不明白什么是错的。你可以看到有6个printf语句。我希望我的程序能够首先查找一个圆的面积和圆周,然后再查找一个正方形的面积和圆周,因此它会要求用户输入圆的直径,然后打印该面积和圆周,接下来它会请求用户输入正方形的长度,然后打印正方形的面积和周长。问题是当我运行我的代码时,它要求输入直径,然后打印区域和周长,然后在那里结束。它不要求输入正方形的长度。我的代码运行不正常
#include <stdio.h>
int main (void) {
//Circle
const float Pi = 3.142;
float radius = 0.0;
float dia = 0.0;
float area = 0.0;
float circum = 0.0;
printf("Input the diameter of the circle:");
scanf("%f", &dia);
radius = dia/2;
area = radius*radius*Pi;
circum = 2*Pi*radius;
printf("\nThe area of the circle is %.2f",area);
printf("\nThe circumference of the circle is %.2f",circum);
//Square
float len = 0.0;
float areaS = 0.0;
float periS = 0.0;
printf("\nInput the length of the square:");
scanf("%f",&len);
areaS = len*len;
periS = 4*len;
printf("The area of the square is %.2f", areaS);
printf("The perimeter of the square is %.2f", periS);
return 0;
}
怎么回事? –
请您详细说明一下吗?你有构建错误吗?你有运行时错误(崩溃)?你有意想不到的输出? –