gpt4 book ai didi

c - 如何将这个 ifs 语句转换为 switch 语句。用C语言

转载 作者:行者123 更新时间:2023-11-30 20:29:24 25 4
gpt4 key购买 nike

int op_type(const char *input, int op_pos)
{
int category;

if (input[op_pos] == '+')
category = 1;

if (input[op_pos] == '*')
category = 2;

if (input[op_pos] == '/')
category = 3;

if (input[op_pos] == '^')
category = 4;

return category;
}

此函数将用于进行基本数学计算。

最佳答案

理论上答案应该是:

int op_type(const char *input, int op_pos)
{
int category;
switch (input[op_pos]){
case '+':
category = 1;
break;
case '*':
category = 2;
break;
case '/':
category = 3;
break;
case '^':
category = 4;
break;
}
return category;
}

希望这能回答您的问题。

关于c - 如何将这个 ifs 语句转换为 switch 语句。用C语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58251679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com