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