编写一段C语言程序,要求输入一行字符,找出其中的大写字母、小写字母、空格、数字以及其他字符的个数。

来自:    更新日期:早些时候
c语言用指针编写,输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?~

#include
void main()
{
int a=0,b=0,c=0,d=0,e=0,i=0;
char *p,s[20];
while((s[i]=getchar())!='
')i++;
p=s;
while(*p!=10)
{
if(*p>='A'&&*p<='Z')
a++;
else if(*p>='a'&&*p<='z')
b++;
else if(*p==' ')
c++;
else if(*p>='0'&&*p<='9')
d++;
else e++;
p++;
}
printf("大写字母 %d 小写字母 %d
",a,b);
printf("空格 %d 数字 %d 非字符 %d
",c,d,e);
}

#includevoid main() { char s[256],*p; int a,b,c,d; gets(s); p=s; a=b=c=d=0; while ( *p!=0 ) { if ( *p>='A' && *p='0' && *p<='9' ) c++; else d++; p++; } printf("大写字母%d,空格%d,数字%d,其他%d。
",a,b,c,d);}

代码资料:

#include "stdio.h"

int main(int argc,char *argv[]){

char s[300];

int i,uc,lc,sp,di,ot;

printf("Please enter a string...
");

i=0;

while(s[i]=getchar(),s[i]!='
' && ++i<300);

uc=lc=sp=di=ot=0;

for(s[i]='\0',i=0;s[i];i++)

if(s[i]>='A' && s[i]<='Z')

uc++;

else if(s[i]>='a' && s[i]<='z')

lc++;

else if(s[i]==' ')

sp++;

else if(s[i]>='0' && s[i]<='9')

di++;

else

ot++;

printf("UPPERCASE: %d
LOWERCASE: %d
",uc,lc);

printf("    SPACE: %d
    DIGIT: %d
    OTHER: %d
",sp,di,ot);

return 0;

}



#include"stdio.h"

#include"string.h"


int main(){

char str[100];

int i,a=0,b=0,c=0,d=0,e=0;

gets(str);

for(i=0;i<strlen(str);i++){

if(str[i]>='A'&&str[i]<='Z'){

a++;

}else if(str[i]>='a'&&str[i]<='z'){

b++;

}else if(str[i]==' '){

c++;

} else if(str[i]>='0'&&str[i]<='9'){

d++;

}else{

e++;

}

}

printf("大写字母:%d个
",a);

printf("小写字母:%d个
",b);

printf("空格    :%d个
",c);

printf("数字    :%d个
",d);

printf("其他字符:%d个
",e);

    return 0;

}




编写一段C语言程序,要求输入一行字符,找出其中的大写字母、小写字母、空格、数字以及其他字符的个数。视频

相关评论:
  • 18835937604编写一段C语言程序,要求输入一行字符,找出其中的大写字母、小写字母、空...
    卓仲雅int main(int argc,char *argv[]){ char s[300];int i,uc,lc,sp,di,ot;printf("Please enter a string...\\n");i=0;while(s[i]=getchar(),s[i]!='\\n' && ++i<300);uc=lc=sp=di=ot=0;for(s[i]='\\0',i=0;s[i];i++)if(s[i]>='A' && s[i]<='Z')uc++...

  • 18835937604用C语言编写一段程序,要求:输入一段字符,分别统计出其中的英文字母、空...
    卓仲雅\/*分类计数*\/capCnt = lowCnt = numCnt = spaceCnt = othCnt = 0;puts ("输入字符串:");gets (str);while (*p) {if (*p>='A'&&*p<='Z') {cap[capCnt] = *p;capCnt++;}else if (*p>='a'&&*p<='z') {low[lowCnt] = *p;lowCnt++;}else if (*p>='0'...

  • 18835937604用C语言编写一个程序,从键盘上输入一个小写字母,将其本身及对应的大写字...
    卓仲雅prinft("大写字母是:%c\\n",ch);} else(printf("请输入大写字母");)示例三:include <stdio.h> main(){ char c; \/\/声明变量 scanf("%c",&c); \/\/键盘上取值 printf("%c %c",c,ch-'a'+'A');\/\/本身和大写输出 } ...

  • 18835937604编写一个c语言程序,实现录入学生学号和姓名信息的功能
    卓仲雅include<stdio.h> include<stdlib.h> intmain(void){ chars[10];\/\/姓名 intnum;\/\/学号 printf("请输入姓名:\\n");gets(s);printf("请输学号:\\n");scanf("%d",&num);printf("姓名是:%s\\n学号是:%d\\n",s,num);system("pause");return0;} ...

  • 18835937604c语言,要求输入abc..wxyz对应输出efg..abcd,怎么做?谢谢!
    卓仲雅题目意思就是在将字母a ->e;即变成其后的第4个字母,程序如下:include <stdio.h> main(){ char c;while((c=getchar()!='\\n'){if((c>='a'&&c<='z')){ c=c+4;if(c>'z')c=c-26;} printf("%c",c);} }

  • 18835937604编写一段C语言程序,要求输入两个字符串,自定义一个函数,将第一个字符...
    卓仲雅) break; } n=0; while ( *s2 ) { s2++; n++; if ( n>=m ) break; } while ( *s2 ) { *s1=*s2; s1++; s2++; } s1=0;} void main() { char s1[256],s2[256]; int m;gets(s1); gets(s2); scanf("%d",&m); f(s1,s2,m-1); printf("%s\\n",s1);} ...

  • 18835937604C语言编写程序,要求输入x和eps,按上述公式计算sinx的近似值。要求计算的...
    卓仲雅{ int t=0,n,m,i; float eps,sinx=0.0,x,f=1,s=1; scanf("%f%f",&x,&eps); for(m=1; fabs(f)>eps; m+=2) { f=(pow(-1.0,t))*(pow(x,2*t+1))\/s; sinx=sinx+f; s=s*(m+1)*(m+2); t++; } printf("%.2f",sinx); } ...

  • 18835937604c语言程序编写:要求从键盘上输入一个不多于5位数的正整数,依次输出每一...
    卓仲雅include <stdio.h> void main(){ int n;scanf("%d",&n);if(n\/100000)printf("应输入一个不多于5位数的正整数!\\n");else { printf("%d",n%10);n\/=10;while(n){ printf(",%d",n%10);n\/=10;} } }

  • 18835937604用C语言写出实现以下函数的对应程序,要求:输入X,计算并输出函数Y的值...
    卓仲雅include<stdio.h> float x,y;void main(){ printf("Please Input x:\\n");scanf("%f",&x);if(x==0) y=20;else if(x<0)y=x+10;else y=30*x;printf("Y=%5.2f",y);}

  • 18835937604用c语言编写一个程序要求输入一个数,输出该数分别与1—10的数相承的结...
    卓仲雅include"stdio.h"void main(){ int a;printf("请输入一个整数:");scanf("%d",&a);for (int i=1;i<=10;i++){ printf("%d",a);printf("*");printf("%d",i);printf("=");printf("%d\\t",a*i);if (i%2==0)printf("\\n");} } ...

  • 相关主题精彩

    版权声明:本网站为非赢利性站点,内容来自于网络投稿和网络,若有相关事宜,请联系管理员

    Copyright © 喜物网