注册 登录
编程论坛 C语言论坛

怎样用if多分支语句编写

小熊软糖 发布于 2021-12-31 16:21, 1111 次点击
c语言,用if语句编写程序,输入一个星期的某一天,判断这一天是否有c语言课
1 回复
#2
mindfulness2022-01-08 08:58
solution1:
if(xxxx)
{
xxxxx;
}
else if(xxxx)
{
xxxxx;
}
else if(xxxx)
{
xxxxx;
}
...
else
{
xxxxx;
}

solution2:

switch(xxx)
{
case xxx:
    break;
case xxx:
    break;
....
default:
    break;
}

solution3:
change the condition to a int or uint, then use a table to chose it.such as:
/*do some define*/
typedef void (func_t*)(int x)
func_t table[x] = {func1, func2, func3,...}
/*when condition i(the same as if(condition == i) funci)*/
table[i](x)
1