C Language Implementation statistics number of characters

Source: Internet
Author: User

#include<stdio.h> int main() {      int sz[10]={0},zm[26]={0},z[26]={0},i,space=0,e=0,t=0;      char c;      printf ( "请输入一段字符,统计其中各字符的数量\n" );      while ((c= getchar ())!= ‘\n‘ )      {          if (c<= ‘z‘ &&c>= ‘a‘ )              zm[c- ‘a‘ ]++;          else if (c<= ‘Z‘ &&c>= ‘A‘ )              z[c- ‘A‘ ]++;          else if (c<= ‘9‘ &&c>= ‘0‘ )              sz[c- ‘0‘ ]++;          else if (c== ‘ ‘ )              space++;          else              e++;      }      printf ( "\n\n" );      for (i=0;i<=9;i++)      {          t++;          printf ( " %d的个数为%d   " ,i,sz[i]);          if (t%3==0)              printf ( "\n" );      }      t=0;      printf ( "\n\n\n" );      for (i=0;i<=25;i++)      {          t++;          printf ( " %c的个数为%d   " ,i+97,zm[i]);          if (t%3==0)              printf ( "\n" );      }      t=0;      printf ( "\n\n\n" );      for (i=0;i<=25;i++)      {          t++;          printf ( " %c的个数为%d   " ,i+65,z[i]);          if (t%3==0)              printf ( "\n" );      }      t=0;      printf ( "\n\n\n" );      printf ( " 空格的个数为%d\n\n" ,space);      printf ( " 其他字符的个数为%d\n" ,e);      return 0; }

C Language Implementation statistics number of characters

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.