用C语言分别统计一串字符中字母、数字、空格及其它字符的个数。
#include<stdio.h>
int main(){
printf(“请输入一串字符\n”);
char c;
int letters=0,spaces=0,digits=0,others=0;
while((c=getchar())!=’\n’){
if((c>=‘a’&&c<=‘z’)||(c>=‘A’&&c<=‘Z’)){
letters++;
}
else if(c>=‘0’&&c<=‘9’){
digits++;
}
else if(c==’ '){
spaces++;
}
else{
others++;
}
}
printf(“字母:%d,数字:%d,空格:%d,其他:%d\n”,letters,digits,spaces,others);
return 0;
}
输出200以内能被七整除的数
#include<stdio.h>
int main()
{int a[200];
int i;
for(i=0;i<200;i++)
{a[i]=i+1;
if (a[i]%7==0){
printf("%d\n",a[i]);
}
}return 0;
}
2020-11-27
最新推荐文章于 2022-06-08 21:00:38 发布