输入一行文字,找出其中大写字母、小写字母、空格、数字、及其他字符各有多少
编辑: 面试啦 发布时间: 2023-03-27 14:03:55
解: #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);
}
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面试题
面试题库导航
- C++面试题
- JAVA面试题
- Oracle面试题
- MySQL面试题
- Linux面试题
- 网络工程师面试题
- 网管面试题
- 软件工程师面试题
- PHP面试题
- .net面试题
- 软件测试面试题
- EJB面试题
- Spring面试题
- Javascript面试题
- Python面试题
- QTP面试题
- Servlet面试题
- J2EE面试题
- Database面试题
- ASP面试题
- Unix面试题
- Loadrunner面试题
- 通信面试题
- 嵌入式面试题
- Ruby面试题
- Delphi面试题
- Mobile开发面试题
- SOA面试题
- JAVA面试题面试题
- 研发工程师面试题
- 软件架构师面试题
- 系统工程师面试题
- Android面试题
- JAVA程序员
- C#面试题