在c++14标准下调用cmath后是可以直接用M_PI的
在本地vscode下gcc编译是直接用M_PI也是可以编译的
为什么在洛谷选c语言会说M_PI未声明
#include<stdio.h>
#include<math.h>
signed main()
{
int a,b;
double c=M_PI;
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
/tmp/compiler_n4p1ma4t/src: 在函数‘main’中:
/tmp/compiler_n4p1ma4t/src:6:14: 错误:‘M_PI’未声明(在此函数内第一次使用)
double c=M_PI;
^~~~
/tmp/compiler_n4p1ma4t/src:6:14: 附注:每个未声明的标识符在其出现的函数内只报告一次
/tmp/compiler_n4p1ma4t/src:6:12: 警告:未使用的变量‘c’ [-Wunused-variable]
double c=M_PI;
^
洛谷报错
#define M_PI 3.14159265358979323846
math.h中的定义