鱼C论坛

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

[已解决]为什么第一个菱形无法输入

[复制链接]
发表于 2021-11-14 18:06:20 | 显示全部楼层 |阅读模式

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

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

x
#include <stdio.h>

int main() {
        int n;
        int a,b;
        int t;
        char ch;
        int count=0;
        scanf("%d",&t);

        while((scanf("%c %d",&ch,&n))!=EOF) {

                for(int i=1; i<=n; i++) {

                        for(int j=1; j<=n-i; j++) {
                                printf(" ");
                        }
                        for(int j=1; j<=2*i-1; j++) {
                                printf("%c",ch);
                        }
                        printf("\n");
                }
                for(int i=n-1; i>=1; i--) {
                        for(int j=1; j<=n-i; j++) {
                                printf(" ");
                        }
                        for(int j=2*i-1; j>=1; j--) {
                                printf("%c",ch);
                        }
                        printf("\n");
                }

                fflush(stdin);
                count++;
                if(count>t)
                        break;
        }
        return 0;
}
最佳答案
2021-11-14 20:02:36
本帖最后由 jhq999 于 2021-11-14 20:04 编辑

啊!才发现!
  1.         int n;
  2.         int a,b;
  3.         int t;
  4.         char ch;
  5.         int count=0;
  6.         scanf("%d",&t);
  7.         fflush(stdin);//上面这个别忘了清除缓存
复制代码


  1. if(count>=t)
  2.            break;
复制代码

  1. 2
  2. 4 4
  3.      4
  4.    444
  5.   44444
  6. 4444444
  7.   44444
  8.    444
  9.      4
  10. 5 5
  11.     5
  12.    555
  13.   55555
  14. 5555555
  15. 555555555
  16. 5555555
  17.   55555
  18.    555
  19.     5
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-14 19:55:06 | 显示全部楼层

回帖奖励 +1 鱼币

本帖最后由 jhq999 于 2021-11-14 19:56 编辑

没毛病
  1. a 6
  2.      a
  3.     aaa
  4.    aaaaa
  5.   aaaaaaa
  6. aaaaaaaaa
  7. aaaaaaaaaaa
  8. aaaaaaaaa
  9.   aaaaaaa
  10.    aaaaa
  11.     aaa
  12.      a


复制代码

无标题.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-14 20:02:36 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jhq999 于 2021-11-14 20:04 编辑

啊!才发现!
  1.         int n;
  2.         int a,b;
  3.         int t;
  4.         char ch;
  5.         int count=0;
  6.         scanf("%d",&t);
  7.         fflush(stdin);//上面这个别忘了清除缓存
复制代码


  1. if(count>=t)
  2.            break;
复制代码

  1. 2
  2. 4 4
  3.      4
  4.    444
  5.   44444
  6. 4444444
  7.   44444
  8.    444
  9.      4
  10. 5 5
  11.     5
  12.    555
  13.   55555
  14. 5555555
  15. 555555555
  16. 5555555
  17.   55555
  18.    555
  19.     5
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-25 13:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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