编写一个函数,统计一条英文句子中字母的个数,在主程序中实现输入输出。
1 #include <iostream> 2 #include <string> 3 #include<string.h> 4 #include <stdio.h> 5 using namespace std; 6 7 int fun(char *str){ 8 int sum = 0; 9 for(int i = 0; str[i]; i++){ 10 if((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z')) sum++; 11 } 12 return sum; 13 } 14 int main(){ 15 char str[100]; 16 cout<<"输入英文句子"<<endl; 17 gets(str); 18 cout<<"字母个数:"<<fun(str); 19 return 0; 20 21 }
标签:21,int,char,str,&&,include From: https://www.cnblogs.com/YUZE2001/p/17221483.html