Count the number of characters and the number of characters

Source: Internet
Author: User

Count the number of characters and the number of characters

1 // question: enter a line of characters to calculate the numbers of English letters, spaces, numbers, and other characters. 2 // program analysis: Use the while statement, the condition is that the input character is not '\ n '. 3 4 # include <stdio. h> 5 6 int main () 7 {8 char c; 9 int letters = 0, spaces = 0, digits = 0, others = 0; 10 printf ("Please input some characters \ n"); 11 while (c = getchar ())! = '\ N') 12 {13 if (c> = 'A' & c <= 'Z ') | (c> = 'A' & c <= 'Z') 14 letters ++; 15 else if (c> = '0' & c <= '9') 16 digits ++; 17 else if (c = '') 18 spaces ++; 19 else20 others ++; 21} 22 printf ("letters = % d, digits = % d, spaces = % d, others = % d \ n", letters, digits, spaces, others); 23 return 0; 24}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.