鱼C论坛

 找回密码
 立即注册
查看: 2878|回复: 2

c语言:为什么一执行多组数据就自动关闭

[复制链接]
发表于 2019-11-3 14:28:43 | 显示全部楼层 |阅读模式

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

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

x

这要怎么改


  1. #include<stdio.h>
  2. int main()
  3. {
  4.         int num=0;
  5.         char c;
  6.         while(scanf("%c",&c)!=EOF)
  7.         {
  8.                 if(c=='\n')
  9.                 {
  10.            break;
  11.                 }
  12.                 else
  13.                 {
  14.                         if(c>='0'&&c<='9')
  15.                         num=num*10+c-'0';
  16.                 }                       
  17.         }
  18.         printf("%d\n",num);
  19.         getchar();
  20.         return 0;
  21. }
复制代码



Sample Input
Su23h67
123jjj
00UU

Sample Output
2367
123
0



小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-3 14:58:25 | 显示全部楼层
  1. #include <stdio.h>
  2. int main()
  3. {
  4.         unsigned int num = 0                                              ;
  5.         char c                                                            ;
  6.         while(scanf("%c" , & c) != EOF) {
  7.                 if(c =='\n') {
  8.                         printf("%u\n" , num)                              ;
  9.                         fflush(stdout)                                    ;
  10.                         getchar()                                         ;
  11.                 } else {
  12.                         if(c >= '0' && c <= '9') num = num * 10 + c - '0' ;
  13.                 }
  14.         }
  15.         return 0                                                          ;
  16. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-5 22:32:39 | 显示全部楼层

那我这是错哪了,我运行了你的代码后结果不一样欸
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-25 19:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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