//if语句
#inlcude <stdio.h>
#include <math.h>
define a 10 //a自己取值
void main()
{
float x, y;
scanf("%f",&x);
if(x>=0.5 && x<1.5)
y = a*x*x;
if(x>=1.5 && x < 3.5)
y = exp(a*x);
if(x<=3.5 && x<7.5)
y = pow(sin(a+x), 2);
printf("%f", y);
}
//switch语句
#include <stdio.h>
#include <math.h>
define a 10 //a自己取值
void main()
{
float x, y;
scanf("%f",&x);
int n = x/0.5;
switch(n)
case(14):
case(13):
case(12):
case(11):
case(10):
case(9):
case(8):
case(7):
y = pow(sin(a+x), 2);break;
case(6):
case(5):
case(4):
case(3):
y = exp(a*x);break;
case(2):
case(1):
y = a*x*x;break;
default: break;
printf("%d", y);
}
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/6a600c338744ebf87bdcbbe4d9f9d72a6159a7b8?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
“define a 10 //a自己取值”显示Declaration syntax error
怎么办?
追答#define a 10 //宏定义,写错了,前面加个#
本回答被提问者采纳