我不确定这段代码中缺少什么。
我正在创建一个工具,您可以在 C 编程中计算直梯形的周长,但周长线不断出现错误。
#include<stdio.h>
#include<math.h>
int main () {
/* variable definition: */
float baseA, baseB, height, perimeter;
/* Prompt user for baseA */
printf("Enter the first base of the trapezoid: \n");
// Input the base
scanf("%f", &baseA);
/* Prompt user for baseB */
printf("Enter the second base of the trapezoid: \n");
// Input the baseB
scanf("%f", &baseB);
/* Prompt user for height */
printf("Enter the height of the trapezoid: \n");
// Input the height
scanf("%f", &height);
// Calculate the Perimeter
perimeter = baseA + baseB + height + sqrt(height*height + (baseB –
baseA)*(baseB – baseA) );
// Print the result
printf("Perimeter is: %f\n", perimeter);
return 0;}`
用户应该能够输入任何数字并使用 C 代码格式的勾股定理计算直梯形的结果。
最佳答案
您似乎没有使用 -
字符进行除法。我复制了您的代码并收到错误:
error: non-ASCII characters are not allowed outside of literals and identifiers
perimeter = baseA + baseB + height + sqrt(height*height + (baseB – baseA)*(baseB - baseA) );
我刚刚用 -
替换了您的 -
并且它起作用了。
关于计算直梯形的周长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57838582/