我正在教我的兄弟一些C基础知识,这是代码:
/*Program for cicrumference and surface calculation.*/
#include <stdio.h> // Standard input and output.
#define PI 3.141593; // Constant pi.
main() { // Main program.
double r; // Radius.
printf("Enter the radius: "); // Requesting radius input.
scanf("%lf", &r); // Radius input.
printf("\nCircumference: %.6f", r * 2 * PI); // Printing the circumference. // ERR
printf("\nSurface: %.6f", r * r * PI); // Printing the surface. // ERR
getchar(); getchar(); // Pause.
}
我得到这些错误:
错误C2059:语法错误:')'
错误C2143:语法错误:在';'之前缺少')'
同时PI
在printf
函数的第二个参数中将常量用作表达式的一部分。
我做错了什么?
您不必为预处理程序#define
s加上分号(例如,我现在还记得的其他指令也没有:例如,您是否为include
s添加了分号?)。
预处理程序替代是文字型的,它将插入分号,因此最终代码为
printf("\nCircumference: %.6f", r * 2 * 3.141593;);
这显然是语法错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句