面试啦 - 提供专业面试问题及答案、面试技巧、助您成功面试!
您的当前位置:首页 > 面试题库 > IT面试题 > C++面试题 > 正文

输入一行文字,找出其中大写字母、小写字母、空格、数字、及其他字符各有多少

解: #include
main()
{ int upper=0.lower=0,digit=0,space=0,other=0,i=0;
char *p,s[20];
printf(“Input string:”);
while ((s[i]=getcher())!=’\n’) i++;
p=&s[0];
while(*p!=’\n’)
{ if((‘A’<=*p)&&(8p<=’Z’))
++upper;
else if((‘a’<=*p)&&(*p<=”z’))
++lower;
else if(8p= =’’)
++space;
else if((*p<=’9’)&&(*p>=’0’))
++dight;
else
++other;
p++;
}
printf(“upper case:%d lower case:%d”,upper,lower);
printf(“space:%d\ndigit:%d\nother:%d\n”,space,digit,other);
}
词条:c面试题
上一篇:什么是数组名 下一篇:static全局变量与普通的全局变量有什么区别?static局部变量和普通局部变量有什么区别?static函数与普通函数有什么区别?
与该文相关的文章

温馨提示:如果您对面试网有任何建议,请通过网站联系邮箱向我们反馈,感谢各位的建议与支持!