用pascal语言编程:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的
3个回答
2016-08-29
展开全部
#include <stdio.h>
void fun(char str[],int *zm,int *sz,int *kg)
{
int i=0;
while(str[i++]!=0)
if(str[i]>'a'&&str[i]<'z'||str[i]>'A'&&str[i]<'Z') (*zm)++;
else if(str[i]>'0'&&str[i]<'9') (*sz)++;
else if(str[i]==' ') (*kg)++;
}
void main()
{
char str[81];
int zm=0,sz=0,kg=0;
printf("请输入一个字符串(不超过80个)");
gets(str);
fun(str,&zm,&sz,&kg);
printf("其中字母%d个,数字%d个,空格%d个",zm,sz,kg);
}
#include <stdio.h>
#define N 100
main()
{
char all[N];
int i,zimu=0,shuzi=0,qita=0;
printf("请输入一个字符串(不超过100个):");
gets(all);
for(i=0;all[i];i++)
{
if(all[i]>'a'&&all[i]<'z'||all[i]>'A'&&all[i]<'Z')
zimu++;
else if(all[i]>'0'&&all[i]<'9')
shuzi++;
else
qita++;
}
printf("其中字母%d个,数字%d个,其他字符%d个\n",zimu,shuzi,qita);
}
void fun(char str[],int *zm,int *sz,int *kg)
{
int i=0;
while(str[i++]!=0)
if(str[i]>'a'&&str[i]<'z'||str[i]>'A'&&str[i]<'Z') (*zm)++;
else if(str[i]>'0'&&str[i]<'9') (*sz)++;
else if(str[i]==' ') (*kg)++;
}
void main()
{
char str[81];
int zm=0,sz=0,kg=0;
printf("请输入一个字符串(不超过80个)");
gets(str);
fun(str,&zm,&sz,&kg);
printf("其中字母%d个,数字%d个,空格%d个",zm,sz,kg);
}
#include <stdio.h>
#define N 100
main()
{
char all[N];
int i,zimu=0,shuzi=0,qita=0;
printf("请输入一个字符串(不超过100个):");
gets(all);
for(i=0;all[i];i++)
{
if(all[i]>'a'&&all[i]<'z'||all[i]>'A'&&all[i]<'Z')
zimu++;
else if(all[i]>'0'&&all[i]<'9')
shuzi++;
else
qita++;
}
printf("其中字母%d个,数字%d个,其他字符%d个\n",zimu,shuzi,qita);
}
展开全部
program df;
var s:string;
i,z,k,sh,q:longint;
begin
z:=0;
k:=0;
sh:=0;
q:=0;
readln(s);
for i:=1 to length(s) do
if s[i] in ['a'..'z','A'..'Z'] then z:=z+1
else if s[i]=' ' then k:=k+1
else if s[i] in ['1'..'9'] then sh:=sh+1
else q:=q+1;
writeln('you ',z,' ge zi mu');
writeln('you ',k,' ge kong ge');
writeln('you ',sh,' ge shu zi');
writeln('you ',q,' ge qi ta zi fu');
end.
var s:string;
i,z,k,sh,q:longint;
begin
z:=0;
k:=0;
sh:=0;
q:=0;
readln(s);
for i:=1 to length(s) do
if s[i] in ['a'..'z','A'..'Z'] then z:=z+1
else if s[i]=' ' then k:=k+1
else if s[i] in ['1'..'9'] then sh:=sh+1
else q:=q+1;
writeln('you ',z,' ge zi mu');
writeln('you ',k,' ge kong ge');
writeln('you ',sh,' ge shu zi');
writeln('you ',q,' ge qi ta zi fu');
end.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var
c:char;
e,n,s,o:integer;
begin
e:=0; n:=0; s:=0; o:=0;
while not(eoln) do begin
read(c);
if upcase(c) in ['A'..'Z'] then inc(e)
else if c in ['0'..'9'] then inc(n)
else if c=' ' then inc(s)
else inc(o);
end;
readln;
writeln('EnChar:',e,' NumChar:',n,' Space:',s,' Others:',o);
readln;
end.
c:char;
e,n,s,o:integer;
begin
e:=0; n:=0; s:=0; o:=0;
while not(eoln) do begin
read(c);
if upcase(c) in ['A'..'Z'] then inc(e)
else if c in ['0'..'9'] then inc(n)
else if c=' ' then inc(s)
else inc(o);
end;
readln;
writeln('EnChar:',e,' NumChar:',n,' Space:',s,' Others:',o);
readln;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询