oki5330sc:C语言问题,请教一下

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 23:59:36
写一个主函数,输入任意一串字符(以‘#’结束),分别统计出大写字母,小写字母,及其它字符的个数,并将结果输出。

#include "stdio.h"
main()
{
char ch;
int i=0,j=0,k=0;
while((ch=getchar())!='#')
{
if(ch>='a'&&ch<='z') i++;
else if(ch>='A'&&ch<='Z') j++;
else k++;
}
printf("\n%2d%2d%2d",i,j,k);
}

#include <stdio.h>
#include <conio.h>
#define MAXLENGTH
void main()
{
int uppercase=0;
int lowercase=0;
int other=0;
int c;
while(1)
{ c=getch();/*用getchar不好的啦*/
if (c=='#') break;
if (c>='a'&&c<='z') lowercase++;
else if (c>='A'&&c<='Z') uppercase++;
else other++;
}
printf("n of uppercase: %d\n",uppercase);
printf("n of lowercase: %d\n",lowercase);
printf("n of others: %d\n",other);
}