這是我在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;
}
怎麼回事? –
請您詳細說明一下嗎?你有構建錯誤嗎?你有運行時錯誤(崩潰)?你有意想不到的輸出? –