帮忙编程啊,C语言

来源:百度知道 编辑:UC知道 时间:2024/06/18 15:35:45
C语言编程
编程 从键盘输入20个字符,分别统计其中字母字符(不区分大小写)、数字字符和其他

Turbo C2.0 3.0编译
#include<stdio.h>
void main()
{
int letter_num=0,num_num=0,other_num=0;
char c;
printf("input 20 words with the end of ENTER:");
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')
letter_num++;
else if(c>='0'&&c<='9')
num_num++;
else other_num++;
}
printf("the number of letters is%d,the number of num is%d\,the number of other words is%d",letter_num,num_num,other_num);
}

//---------------------------------------------------------------------------

#include <stdio.h>
#include <ctype.h>

int main(void)
{
int i,num=0,alp=0,ot=0;
char ch;
for (i = 0; i<20; i++) {
ch=getchar();
if (isalpha(ch)) alp++;
else if (isdigit(ch)) num++;
else ot++;
}
pr