搜索

【求助】学过C 语言的进

[复制链接]
发表于 2011-11-7 18:01:16 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
饿,很简单。。
发表于 2011-11-7 18:02:12 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
本帖最后由 长乐虾米 于 2011-11-7 18:02 编辑

   while(mima!='a')
    {
        printf("qing chong xin shu ru\n");
        scanf("%c",&mima);
    }


改成
while(1)
    {
if (mima=='a')
break;
        printf("qing chong xin shu ru\n");
        scanf("%c",&mima);
    }

 楼主| 发表于 2011-11-7 21:28:54 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
长乐虾米 发表于 2011-11-7 18:02
while(mima!='a')
    {
        printf("qing chong xin shu ru\n");

你好,你在“while”循环体内加“break”这个强行终止和“if”配合,是没有作用的反而降低的效率,如果不满足条件“a"仍然在”while"循环体内,运行时还是和我原来一样的
 楼主| 发表于 2011-11-7 21:48:55 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
hwwen 发表于 2011-11-7 11:19
printf("qing chong xin shu ru\n");
        scanf("%c",&mima);
把这行 scanf("%c",&mima);去掉,换成g ...

用无条件转移语句"goto"可能是个可行的办法,劳烦在这代码中列出实例,可以吗?我应用的不熟练,总是提示错误
发表于 2011-11-7 22:03:38 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
main()
{
    char mima;
    scanf("%s",&mima);
    while(mima!='a')
    {
        printf("qing chong xin shu ru\n");
        scanf("%s",&mima);
    }
    printf("good\n");
    getch();
}
发表于 2011-11-7 22:04:14 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
main()
{
    char mima;
    scanf("%c",&mima);getchar();
    while(mima!='a')
    {
        printf("qing chong xin shu ru\n");
        scanf("%c",&mima);getchar();
    }
    printf("good\n");
    getch();
}
 楼主| 发表于 2011-11-7 22:37:36 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
犀利的人生 发表于 2011-11-7 22:04
main()
{
    char mima;

谢谢,也不对
发表于 2011-11-7 22:40:36 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
寂寞的独叶草 发表于 2011-11-7 22:37
谢谢,也不对

两个都不行?
发表于 2011-11-7 22:53:06 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
main()
{
    char mima = '0';
    while(getch() != 'a')
    {
        printf("qing chong xin shu ru\n");
    }

    printf("good\n");
    getch();
}
 楼主| 发表于 2011-11-8 00:08:15 | 显示全部楼层 来自 中国福建福州来自: 中国福建福州
犀利的人生 发表于 2011-11-7 22:40
两个都不行?

不好意思,重新试了下上面的那个可以,刚才没看清楚“C”改成了“S”。哈哈,谢谢,请问下为什么用“S”就不会循环两次,而“C”就会循环两次呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

精华帖子
热门图文
快速回复 返回顶部 返回列表