计算直梯形的周长

标签 c

我不确定这段代码中缺少什么。

我正在创建一个工具,您可以在 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/

相关文章:

c - 成功交换上下文后返回函数执行时出现段错误

c++ - 's the difference between application' 是什么输入点地址和可执行起始地址

c - 在 ubuntu 上使用 execve 启动 Gtk 程序时出现 "Gtk-WARNING **: cannot open display: "

c - C语言-Unix环境中的Fscanf和sprint命令

c - 如何拆分 wchar_t 数组并将详细信息分配给 C 中的变量?

c - 左填充文本

c - memcmp 上的段错误

将 C 宏转换为 Actionscript 3

c++ - printf() 函数不起作用

c - 如何编写用指针扫描字符串字符串的程序