鱼C论坛

 找回密码
 立即注册
查看: 1609|回复: 8

[已解决]50鱼币有偿求助!各位帮忙看看

[复制链接]
发表于 2021-11-9 23:36:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int letter,digit,blank,other;
    char c;
    letter=digit=blank=other=0;
   
    printf("Please enter a sentence:");
    while((c=getchar())!='/n')
        {
        if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
            letter++;
        else if(c>='0'&&c<='9')
            digit++;
        else if(c==' ')
            blank++;
        else other++;
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d",letter,blank,digit,other);
   
    return 0;
}
各位能帮我看看吗?不知道为什么这段代码始终运行不了
最佳答案
2021-11-10 07:25:18
  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. int main(void)
  4. {
  5.     int letter, digit, blank, other;
  6.     char c;
  7.     letter = digit = blank = other = 0;

  8.     printf("Please enter a sentence:");
  9.     while ((c = getchar()) != '\n') // 应该是\n,/n是错的
  10.     {
  11.         if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
  12.             letter++;
  13.         else if (c >= '0' && c <= '9')
  14.             digit++;
  15.         else if (c == ' ')
  16.             blank++;
  17.         else
  18.             other++;
  19.     }
  20.     printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);

  21.     return 0;
  22. }
复制代码
屏幕截图 2021-11-09 233449.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-9 23:41:38 | 显示全部楼层

回帖奖励 +10 鱼币

不懂C
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-9 23:47:05 | 显示全部楼层

回帖奖励 +10 鱼币

回车符打错了,是\n
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-11-10 07:07:53 | 显示全部楼层

回帖奖励 +10 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-10 07:25:18 | 显示全部楼层    本楼为最佳答案   

回帖奖励 +10 鱼币

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. int main(void)
  4. {
  5.     int letter, digit, blank, other;
  6.     char c;
  7.     letter = digit = blank = other = 0;

  8.     printf("Please enter a sentence:");
  9.     while ((c = getchar()) != '\n') // 应该是\n,/n是错的
  10.     {
  11.         if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
  12.             letter++;
  13.         else if (c >= '0' && c <= '9')
  14.             digit++;
  15.         else if (c == ' ')
  16.             blank++;
  17.         else
  18.             other++;
  19.     }
  20.     printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);

  21.     return 0;
  22. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-10 08:05:40 | 显示全部楼层

回帖奖励 +10 鱼币

楼上已经有答案。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-10 11:01:39 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-10 14:49:49 | 显示全部楼层
看答案  


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-21 11:11:08 | 显示全部楼层
学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 11:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表