c语言 8-9

1、

#include <stdio.h>

int main(void)
{
    int ch;
    int rows = 0;
    
    while((ch = getchar()) != EOF)
    {
        switch(ch)
        {
            case '\n': rows++; break;
        }
    }
    
    printf("number of rows: %d\n", rows);
    return 0;
}

 

 

2、

#include <stdio.h>

int main(void)
{
    int ch;
    int rows = 0;
    
    while((ch = getchar()) != EOF)
    {
        if(ch == '\n')
            rows++;
    }
    printf("number of rows:  %d\n", rows);
    return 0;
}

 

 

3、

#include <stdio.h>

int main(void)
{
    int ch;
    int rows = 0;
    
    while( ch = getchar())
    {
        if(ch == EOF)
            break;
        if(ch == '\n')
            rows++;            
    }
    printf("number of rows: %d\n", rows);
    
    return 0;
}

 

posted @ 2021-05-24 09:10  小鲨鱼2018  阅读(57)  评论(0编辑  收藏  举报