gpt4 book ai didi

C 编程 字符串打印

转载 作者:行者123 更新时间:2023-11-30 18:37:48 24 4
gpt4 key购买 nike

我对此字符串有疑问。

例如:

char ex1[20]="Hello hi";
int choose;
scanf("%d",&choose);

如何才能让用户输入1时打印“hi”,输入0时打印“hello”?

感谢您的帮助。

最佳答案

最简单的解决方案是:

if(choose == 1)
printf("Hello\n");
else if(choose == 0)
printf("hi\n");
else
printf("Please enter 1 or 0.\n");

这里不需要 ex1

关于C 编程 字符串打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35881294/

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