gpt4 book ai didi

C:写一个循环来打印两个字符之间的字母表

转载 作者:太空宇宙 更新时间:2023-11-04 02:32:51 24 4
gpt4 key购买 nike

<分区>

我被赋予了一个非常简单的任务,即编写一个程序,该程序将接受两个字符,然后使用 for() 循环打印它们之间的字母。

这是我的代码:

#include <stdio.h>
int main() {
char a, b;

printf("\nEnter the first character: ");
scanf("%c", &a);

printf("\nEnter the second character: ");
scanf("%c", &b);

for(char i = a; i <= b; i++) {
printf("%c ", i);
}

return 0;
}

当我运行它时,系统会提示我正确输入第一个字符,但当我按下回车键时,它只运行下一个 printf() 然后终止。

编译时没有错误或警告或任何内容。我发现显然已解决的另一个类似问题对我也不起作用。

提前致谢。

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