// 你绝对满意。#include <stdio.h>#define MAXN 1000char a[ MAXN ];int main(){ int words, numbers , flags , blanks ; printf("请输入一串连续的字符:\n"); while( gets(a) ) { words = 0; numbers = 0; flags = 0; blanks = 0; for( int i = 0 ; a[i]!='\0' ; i ++ ) { if( (a[i] >= 'a' && a[i] <= 'z') || ( a[i] >= 'A' && a[i] <= 'Z' ) ) { words++; } else if( a[i] >='0' && a[i]<='9' ) { numbers++; } else if( a[i] == ' ' ) { blanks++; } else { flags++; } } printf("字母个数 %d\n数字个数 %d\n空格个数 %d\n其他字符个数 %d\n\n",words,numbers,blanks,flags); printf("请输入一串连续的字符:\n"); } return 0;} /*请输入一串连续的字符:fs/ . w / 31 54cv 21字母个数 5数字个数 6空格个数 6其他字符个数 3*/
#include <stdio.h>int main(){ char a[20]; int i,num,space,al,ot; printf("input 20 chars:\n"); for(i=0;i<20;i++)a[i]=getchar(); for(i=0,num=0,space=0,al=0,ot=0;i<20;i++) { if(a[i]>='0'&&a[i]<='9')num++; else if(a[i]>='a'&&a[i]<='z')al++; else if(a[i]>='A'&&a[i]<='Z')al++; else if(a[i]==' ')space++; else ot++; } for(i=0;i<20;i++)putchar(a[i]); printf("\n alpha: %d\n number: %d\n space: %d\n other: %d\n" ,al,num,space,ot); return 0;}