"C Language and Programming" Project 2-28-2: Character statistics

Source: Internet
Author: User

Problem Description:

Please compile the program separately to complete the following processing:
(1) Statistics on the number of occurrences of the letter ' A ';
(2) The number of letters (large/lowercase) in the statistical string;
(3) Count of each vowel letter
(4) Count the number of occurrences of each digit character;
Tip: You can define an array of int a[10], save the number of occurrences of ' 0 '-' 9 ' in a string (example A[0] representing the number of characters ' 0 ')
(5) Count the number of occurrences of each letter

#include "stdafx.h" #include <string.h> #include <ctype.h>int main () {char str[99];p rintf ("Please input the String: "); gets_s (str,99); int i (0), a_num (0); while (Str[i]) {if (str[i] = = ' a ') {a_num++;} i++;} printf ("Number of letter A is%d.\n", a_num); i = 0; int Upper_num (0), Lower_num (0), while (Str[i]) {if (Iswlower (Str[i])) {lower_num++;} if (Iswupper (Str[i])) {upper_num++;} i++;} printf ("Number of lowercase letter was%d, uppercase is%d.\n", Lower_num, upper_num); i = 0; int vowel_num[5] = {0,0,0,0,0};while (str[i]) {switch (Str[i]) {case ' a ': vowel_num[0]++; Break;case ' e ': vowel_num[1]++; Break;case ' i ': vowel_num[2]++; Break;case ' o ': vowel_num[3]++; Break;case ' u ': vowel_num[4]++; Break;default:break;} i++;} printf ("Number of vowel letters:\n");p rintf ("\ta\te\ti\to\tu\n"); for (int i = 0; i < 5; i++) {printf ("\t%d", vowel_num[i ]);} printf ("\ n"); i = 0; static int digit_num[10];for (int i = 0; str[i]; i++) {if (IsDigit (Str[i])) {digit_num[str[i]-' 0 ']++;}} printf ("Number of digits:\n"); for (int i= 0; I < 10; i++) {printf ("\tnumber%d", I);} printf ("\ n"); for (int i = 0; i < i++) {printf ("\t%d", Digit_num[i]);} printf ("\ n"); i = 0; static int alpha_num[26];for (int i = 0; str[i]; i++) {if (Isalpha (Str[i])) {if (Isupper (Str[i])) {Str[i] + = ' A '-' a ';} Alpha_num[str[i]-' a ']++;}} printf ("Number of each letter:\n"); for (int i = 0;i<27; i++) {if (Alpha_num[i]!=0) {printf ("%c =%d\n", ' A ' +i, Alpha_nu M[i]);}} printf ("Others is none.");    printf ("\ n"); return 0;}

  

Feelings:

Use this tool site to easily query the function and its usage

http://www.runoob.com/

=

"C Language and Programming" Project 2-28-2: Character statistics

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.