• 计数程序


    1:字符计数

    #include<stdio.h>
    main()
    {
        char c;
        double n=0;    //注意可以使用double 类型
        while((c=getchar())!=EOF)
        n++;
        printf("%.0f",n);
    }

    2:行计数

    #include<stdio.h>
    main()
    {
        char c;
        int n=0;    //注意可以使用double 类型
        while((c=getchar())!=EOF)
        if(c=='\n')
        { n++;
        printf("%d\n",n);
        }
    }

    3:统计单词字符行数

    #include<stdio.h>
    #define IN 1
    #define OUT 0
    main()
    {
        int c,nl,nw,nc,state;//字符,行数,单词数,字符数,状态
       
        state=OUT;
        nl=nw=nc=0;
        while((c=getchar())!=EOF)
        {
            nc++;
            if(c=='\n')
            ++nl;
            if(c=='\n'||c==' '||c=='\t')
            state=OUT;
            else if(state==OUT)
            {
                state=IN;
                ++nw;
            }
        }
        printf("%d %d %d \n",nl,nw,nc);
    }

  • 相关阅读:
    我们的回忆

    出差
    恍惚
    七夕
    K8S命令(一)——Node相关
    K8S命令(二)——查询相关
    [转载]为什么你应该(从现在开始就)写博客
    替代JDK日期的开源项目:jodatime
    使用getElementById获取xml中的指定元素
  • 原文地址:https://www.cnblogs.com/macula7/p/1960655.html
Copyright © 2020-2023  润新知