c语言无内嵌的if的含义

如题所述

第1个回答  2022-02-06
无内嵌的if为“...是真的吗”的意思。c语言if是:是指中用来判定所给定的条件是否满足,根据判定的结果(真或假)决定执行给出的两种操作之一。
在C语言中,if在内嵌与非内嵌中,有以下:
不嵌套
int calculate(int x)
{
int result = 0;

if(x <= -5 || x >= 10)
printf("输入超出");
if(x >= -5 && x < 0)
result = x;
if(x == 0)
result = x - 1;
if(x > 0 && x < 10)
result = x + 1;
return result;
}
//嵌套
int calculate(int x)
{
int result = 0;

if(x <= -5 || x >= 10)
printf("输入超出定义域");
else
{
if(x >= -5 && x < 0)
result = x;
else
{
if(x == 0)
result = x - 1;
else
result = x + 1;
}
}
return result;
}
//switch
int calculate(int x)
{
int result = 0;
int s = -1;

if(x >= -5 && x < 0)
s = 1;
if(x == 0)
s = 2;
if(x > 0 && x < 10)
s = 3;
switch(x)
{
case 1:
result = x;
case 2:
result = x - 1;
case 3:
result = x + 1;
defualt:
printf("输入超出定义域");
}
return result;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网