C语言统计字符数算法

mac2022-06-30  75

#include<stdio.h>#define MAX 100void cal_num(char *str,int count[]){ char *pstr=str; while(*pstr!=0) { if(*pstr>='0'&&*pstr<='9') count[0]++; else if((*pstr>='a'&&*pstr<='z')||(*pstr>='A'&&*pstr<='Z')) count[1]++; else count[2]++; pstr++; }}

int main(){ char str[MAX]; int count[3]={0}; printf("请输入字符串:\n"); scanf("%s",str); cal_num(str,count); printf("数字个数:%d\n",count[0]); printf("字母个数:%d\n",count[1]); printf("特殊字符:%d\n",count[2]); return 0; }

转载于:https://www.cnblogs.com/yangxuechen/p/7218612.html

相关资源:C语言统计26个字符的个数
最新回复(0)