Enter a string of strings. Counting the number of English letters, spaces, numbers, respectively

tags: c

#include <stdio.h>
int main()
{
    int a,b,c,d,ch;
    a=b=c=d=0;// The counter is initialized to 0.
    while((ch=getchar())!='\n')// Cycle read characters to the end of the wrap.
    {
        if(ch>='0' && ch<='9')//number
            a++;
        else if((ch>='a' && ch<='z')||(ch>='A' && ch<='Z'))//letter
            b++;
        else if(ch==' ')// space
            c++;
        else //other
            d++;
    }
    printf("%d %d %d %d\n", a,b,c,d);// Output result.
    return 0;
}

Intelligent Recommendation

Enter a line of characters, count the number of English letters, spaces, numbers, and other characters, respectively.

First, the title is brief Enter a line of characters, count the number of English letters, spaces, numbers, and other characters, respectively. Second, the topic analysis Analysis of Algorithms: Use l...

Huawei OJ - Enter a line of characters, statistics to the number of English letters, spaces, numbers, and other characters, respectively

Topic description Enter a line of characters, statistics to the number of English letters, spaces, numbers, and other characters, respectively. Input description: Enter a line of strings, you can have...

Enter a line of characters, statistics to the number of English letters, spaces, numbers, and other characters, respectively.

Enter a line of characters, statistics to the number of English letters, spaces, numbers, and other characters, respectively. The key to this question is the format of the output:...

Java: Enter a line of characters to count the number of English letters, spaces, numbers, and other characters, respectively.

Program analysis: Use the While statement, the condition is not the input character is not '\ n'. code show as below: The first: operation result: Second: operation result:...

More Recommendation

15. Enter a line of characters to count the number of English letters, spaces, numbers, and other characters, respectively.

Program Book Algorithm - JS Edition Enter a line of characters, count the number of English letters, spaces, numbers, and other characters, respectively. Source console...

[Algorithm] Enter a line of characters, statistics of the number of English letters, spaces, numbers, and other characters, respectively.

When statistics, the number of types, as long as the specific type of heavy character is removed, the original length - the remaining length = a particular type of number. Regular expressions can quic...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top