C语言题目输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。
#include<stdio.h>intmain(){intletter=0,space=0,number=0,others=0;charnextchar;printf(...
#include <stdio.h>
int main()
{
int letter=0,space=0,number=0,others=0;
char nextchar;
printf("Input your string\n");
for(;nextchar!='\n';)
{
scanf("%c",&nextchar);
if('a'<=nextchar<='z'||'A'<=nextchar<='Z')
letter++;
else if(nextchar==' ')
space++;
else if('0'<=nextchar<='9')
number++;
else
others++;
}
printf("letter=%d,space=%d,number=%d,others=%d\n",letter,space,number,others);
}
哪错啦 展开
int main()
{
int letter=0,space=0,number=0,others=0;
char nextchar;
printf("Input your string\n");
for(;nextchar!='\n';)
{
scanf("%c",&nextchar);
if('a'<=nextchar<='z'||'A'<=nextchar<='Z')
letter++;
else if(nextchar==' ')
space++;
else if('0'<=nextchar<='9')
number++;
else
others++;
}
printf("letter=%d,space=%d,number=%d,others=%d\n",letter,space,number,others);
}
哪错啦 展开
69个回答
展开全部
第N次回答这个问题了
#include <stdio.h>
#include <string.h>
bool isChar(char ch);
bool isInt (char ch);
bool isSpace(char ch);
int main()
{
int n_Char = 0, n_Int = 0, n_Others = 0, n_Space = 0;
int i = 0;
char str[80] = {'\0'};
gets(str);
while(str[i] != '\0')
{
if(isChar(str[i]))
n_Char++;
else if(isInt(str[i]))
n_Int++;
else if(isSpace(str[i]))
n_Space++;
else
n_Others++;
++i;
}
printf("char:%d, int:%d, space:%d, others:%d\n", n_Char, n_Int, n_Space, n_Others);
return 0;
}
bool isChar(char ch)
{
if((ch>='a'&&ch<='z') || (ch>='A'&&ch<='Z'))
return true;
else
return false;
}
bool isInt(char ch)
{
if(ch >= '0' && ch <= '9')
return true;
else
return false;
}
bool isSpace(char ch)
{
if(ch == ' ')
return true;
else
return false;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <string.h>
int main()
{
char a[50];
int letter=0,blank=0,number=0,other=0,i,len;
gets(a);
len = strlen(a); // 保存字符串长度
for(i=0;i<len;i++) {
char c = a[i];
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
letter++;
else if(c==' ')
blank++;
else if(c>='0'&&c<='9')
number++;
else other++;
}
printf("letter=%d,blank=%d,number=%d,other=%d\n",letter,blank,number,other);
return 0;
}
#include <string.h>
int main()
{
char a[50];
int letter=0,blank=0,number=0,other=0,i,len;
gets(a);
len = strlen(a); // 保存字符串长度
for(i=0;i<len;i++) {
char c = a[i];
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
letter++;
else if(c==' ')
blank++;
else if(c>='0'&&c<='9')
number++;
else other++;
}
printf("letter=%d,blank=%d,number=%d,other=%d\n",letter,blank,number,other);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-08-29
展开全部
clear
accept "请输入一串字符:" to x
store 0 to dyw,xyw,kg,sz,qt
m=len(x)
for i=1 to m
x1=substr(x,i,1)
k=asc(x1)
do case
case k=32
kg=kg+1
case k>=48 and k<=57
sz=sz+1
case k>=65 and k<=90
dyw=dyw+1
case k>=97 and k<=122
xyw=xyw+1
other
qt=qt+1
endcase
endfor
?"其中空格有: "+alltrim(str(kg))+"个"
?"大写字母有: "+alltrim(str(dyw))+"个"
?"小写字母有: "+alltrim(str(xyw))+"个"
?"数字有: "+alltrim(str(sz))+"个"
?"其它字符有: "+alltrim(str(qt))+"个"
accept "请输入一串字符:" to x
store 0 to dyw,xyw,kg,sz,qt
m=len(x)
for i=1 to m
x1=substr(x,i,1)
k=asc(x1)
do case
case k=32
kg=kg+1
case k>=48 and k<=57
sz=sz+1
case k>=65 and k<=90
dyw=dyw+1
case k>=97 and k<=122
xyw=xyw+1
other
qt=qt+1
endcase
endfor
?"其中空格有: "+alltrim(str(kg))+"个"
?"大写字母有: "+alltrim(str(dyw))+"个"
?"小写字母有: "+alltrim(str(xyw))+"个"
?"数字有: "+alltrim(str(sz))+"个"
?"其它字符有: "+alltrim(str(qt))+"个"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int main()
{int i,zm=0,sz=0,kg=0,qt=0;
char s[200];
gets(s);
for(i=0;s[i];i++)
if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')zm++;
else if(s[i]>='0'&&s[i]<='9')sz++;
else if(s[i]==' ')kg++;
else qt++;
printf("英文字母:%d\n",zm);
printf("数字:%d\n",sz);
printf("空格:%d\n",kg);
printf("其它字符:%d\n",qt);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
void countof(char *pArry,int *pletter,int *pspace,int *pnumber,int *pother){
char cx;
for(;*pArry;pArry++){
if((cx=*pArry)>64 && cx<91 || cx>96 && cx<123) (*pletter)++;
else if(cx==' ') (*pspace)++;
else if(cx<0x3A && cx>0x2F) (*pnumber)++;
else (*pother)++;
}
}
void main(void){
char Arry[500];
int letter,space,number,other;
letter=space=number=other=0;
printf("Type a long string...\nStr=");
gets(Arry);
countof(Arry,&letter,&space,&number,&other);
printf("Letter=%d\nSpace=%d\nNumber=%d\nOther=%d\n",letter,space,number,other);
}
void countof(char *pArry,int *pletter,int *pspace,int *pnumber,int *pother){
char cx;
for(;*pArry;pArry++){
if((cx=*pArry)>64 && cx<91 || cx>96 && cx<123) (*pletter)++;
else if(cx==' ') (*pspace)++;
else if(cx<0x3A && cx>0x2F) (*pnumber)++;
else (*pother)++;
}
}
void main(void){
char Arry[500];
int letter,space,number,other;
letter=space=number=other=0;
printf("Type a long string...\nStr=");
gets(Arry);
countof(Arry,&letter,&space,&number,&other);
printf("Letter=%d\nSpace=%d\nNumber=%d\nOther=%d\n",letter,space,number,other);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询