2、用C语言编写一个程序,从键盘上输入若干个字符,以符号“@”结束,统计这些符号的

作者&投稿:赏邢 (联系方式在网页底部的电邮联系)
编写程序,从键盘输入一行字符,一回车键为结束,分别统计其中的大写字母,小写字母,空格,数字和其他字符的个~

#include "stdio.h"
main()
{char c,sum1=0,sum2=0,space=0,number=0,other=0;
c=getchar();
while(c!='
')
{
if(c>='A'&&c<='Z') sum1++;
else if(c>='a'&&c<='z') sum2++;
else if(c>='0'&&c<='9') number++;
else if(c==' ') space++;
else other ++;
c=getchar();
}
printf("%d,%d,%d,%d,%d",sum1,sum2,space,number,other);
}

#include "stdio.h"
main()
{char c,sum1=0,sum2=0,number=0;
c=getchar();
while(c!='#')
{
if(c>='A'&&c<='Z') sum1++;
else if(c>='a'&&c<='z') sum2++;
else if(c>='0'&&c<='9') number++;
c=getchar();
}
printf("大写字母:%d,小写字母:%d,数字:%d",sum1,sum2,number);
}

#include <stdio.h>

fun(char *str)
{ int total,i=1;
printf("输入字符串,以@结束:");
str[1]=getche();
while(str[i]!='@')
{ i++; str[i]=getche(); }
str[0]=i;
printf("\n");
for(i=1;i<str[0];i++)
putch(str[i]);
}

main()
{ char str[50];
fun(str);
system("pause");
}

函数getche是带有回显但不需要回车的读入方式;如果读入不要回显可以使用getch函数。

char *m=a,*n=a+1;
*m=*n=0;
while(*str!='@'){
m=a;
while(m<n){m++;
if(*m==*str){break;}
}
if(m==n && *n!=*str){n++;*n=*str;*a++;}
str++;
}

#include"iostream.h"
#include<stdio.h>
void main()
{
char c;
int count=0,i=1;
char a[10];//10个足够用了
c=getchar();
while(c!='@')
{
a[i++]=c;
count++;
c=getchar();
}
a[0]=count;
for(int j=1;j<=a[0];j++)
cout<<a[j];
}

相关视频

c语言编写一个程序,非常简单
%f",&b,&y,&r);x=b*(pow(1+r,y)-1)*(1-0.2)printf("利息:%.0f\n",x);}第二题...

用C语言编写一个程序,只要符合要求我继续加分。要详细的我黏贴一下就好...
下列程序,用TC2.0编译、调试成功。include <stdio.h> void main(void){ unsigned char i = 0, IN_temp, IN_num[255], IN_amount[10] = {0,0,0,0,0,0,0,0,0,0};float Total = 0, Aver;while (1) { printf("\\n\\nPlease Input 0~9, Others is Exit.\\n\\n");scanf(...