c语言 8-9

1、

#include <stdio.h>

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

2、

#include <stdio.h>

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

3、

#include <stdio.h>

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

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14802955.html