#include
float f1(float x){ //不用嵌套if
float t;
if(-5
if(0
}
float f2(float x){ //嵌套if
float t;
if (-5
if(-5
if(-5
}// 第三层
}// 第二层
}// 第一层
return t;
}
float f3(float x){ //if~else语句
float t;
if (-5
else if(0
}
float f4(float x){ //switch语句
float t;
int flag = (x<0 ? -1 : x==0 ? 0 : 1);
switch (flag) {
case (-1): t=x; break;
case (0): t=x-1; break;
case (1): t=x+1; break;
}
return t;
}
int main() {
float x, y;
scanf("%f", &x);
y=f1(x);
printf("%f\n", y);
y=f2(x);
printf("%f\n", y);
y=f3(x);
printf("%f\n", y);
y=f4(x);
printf("%f\n", y);
return 0;
}
#include
void main()
{
int x;
int y;
printf("请输入X的值,-5
if(x=0)
y=x-1;
printf("%d",y);
else
y=x+1;
printf("%d",y);
}
#include
void main()
{
int x;
int y;
printf("请输入X的值,-5
switch(y)
{
case x=0:y=x-1;
break;
case x>0&&x<10:y=x+1;
break;
}
printf("%d",y);
}