c语言,编程实现,输入一行字符,分别统计其中英文字母,空格 ,数字和其它字符的个数。

作者&投稿:紫虏 (若有异议请与网页底部的电邮联系)
~ main()
{
int
zm=0,kg=0,sz=0,qt=0;
char
c;
while(
(c
=
getchar())
!=
'\n'
)
//c=getchar是从键盘获取一个字符并赋值给c,\n是换行的意思
{
if(
(c>='a'&&c<='z')
||
(c>='A'&&c<='Z')
)
zm++;
else
if(
c>='0'&&c<='9'
)
sz++;
else
if(
c=='
'
)
kg++;
else
qt++;
}
printf("字母=%d,数字=%d,空格=%d,其他=%d\n",zm,sz,kg,qt);
}

以下程序在win-tc下调试通过
/*
输入一行文字
找出其中大写字母小写字母空格数字及其他字符各有多少
*/
#
include
"stdio.h"
#
include
"conio.h"
void
main(void)
{
int
upper=0,lower=0,digit=0,space=0,other=0,i=0;
char
*p,s[80];
printf("\ninput
a
string:");
while
((s[i]=getchar())!='\n')
i++;
p=s;
while(*p!='\n')
{if((*p>='a')&&(*p<='z'))
upper++;
else
if((*p>='a')&&(*p<='z'))
lower++;
else
if(*p=='
'||*p==9)
space++;
else
if((*p>='0')&&(*p<='9'))
digit++;
else
other++;
p++;
}
printf("upper
case:%d
lower
case:%d
",upper,lower);
printf("space:%d
digit:%d
other:%d
",space,digit,other);
getch();
}


用C#语言编程,如何实现1~4的输出?
1、新建一个工程和.c文件 ,输入头文件和主函数。2、定义 变量类型,输入数字。3、用while语句判断数字是否在1到4范围内。4、调用函数。5、用一个for语句输出。6、编译、运行 ,得到最后的结果。

c语言程序设计答案 编程实现,从键盘输入一个字符,则输出其后的字符,如...
define _CRT_SECURE_NO_WARNINGS\/\/VS环境下需要,VC不需要 include<stdio.h> void main(){ char a;\/\/定义一个字符 printf("请输入一个字符:");\/\/文字提示 scanf("%c", &a);\/\/输入一个字符 printf("其后续字符为:");\/\/文字提示 printf("%c\\n", a + 1);\/\/输出其之后的字符 } ...

编程实现:输入一组学生的姓名和成绩,根据成绩降序排名。
include <stdio.h> include <string.h> define N 3 struct student { int score;char name[20];};main(){ struct student a[N],temp;int i,j;for(i=0;i<N;i++){ printf("input the %dth student's information:\\n",i+1);printf("name:");scanf("%s",a[i].name);printf("s...

...编程实现,使用C语言编写从屏幕上输出两句话: ①C 语言程序设计...
int main(){ printf("C 语言程序设计! \\n");printf("祝你学习顺利!\\n");return 0;}

请问大神,C语言题,编程功能实现:输入一个字符串,输出字符串中的数字部分...
void main(){char str[50];int i=0; \/\/i是数组下标. gets(str); \/\/输入字符串.int s=0;while(str[i]) \/\/当数组元素不是字符串结束符时.执行while{ if(str[i]>='0'&&str[i]<='9') \/\/如果数组元素是数字. 就输出这个元素. { s=s*10+int(str[i])-int('0');...

C语言编程:编程实现将一个数组逆序输出
include<stdio.h> int main(){ int a[5]={1,2,3,4,5};int i;for(i=4;i>=0;i--){ printf("%d",a);} printf("\\n");return 0;}

编程实现输入千米数,输出显示其英里数。 已知:1英里=1.60934千米。_百度...
代码如下:include using namespace std;int main(){ float a,b;cout<<"请输入千米数"<<endl;cin>>a;b=a\/1.60934;cout<<"英里数"<<b<<endl;return 0;}

C语言编程,编程实现怎样将一个数组逆序输出?
实现代码如下:include"stdio.h"void main(){int a[100],n,m;printf("请输入元素的个数:");scanf("%d",&n);printf("请依次输入%d个数:",n);for(m=0;m<n;m++)scanf("%d",&a[m]);printf("按逆序输出为:");for(m=n-1;m>=0;m--)printf("%d ",a[m]);}执行结果 C语言...

编程实现:输入正整数x,求1!+2!+3!+…+x!(要求用两种循环语句实现)。求...
两种方式如下,请采纳 include <stdio.h>long long fac(int n){ if(n==1||n==0) return 1; return n * fac(n-1);}int main(){ int x; printf("请输入x:"); scanf("%d",&x); long long sum = 0; for(int i=1;i<=x;i++) sum+=fac(i); printf("和为:%d\\n",...

C语言编程题 4.编程实现:由用户从键盘输入一串字符(以回车键结束),统 ...
include<stdio.h>#include<stdlib.h>int main(){ char a[128]; gets(a); int i=0; int c1,c2,c3,c4; c1=c2=c3=c4=0; while(a[i++]) { if(a[i]>='A'&& a[i]<='Z') c1++; else if(a[i]>='a'&& a[i]<='z') c2++; else if...

西岗区13083087847: 用C语言编程:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数. -
商若头孢: #include <stdio.h> void main() {char line[30];int i,count1=0,count2=0,count3=0,count4=0;printf("\n请输入一行字符: ");gets(line);i=0;while(line[i]!='\0'){if(((line[i]>=97) && (line[i]<=122))||((line[i]>=65) && (line[i]<=90))){count1++;}...

西岗区13083087847: 用c程序表示输入一行字符,分别统计出其英文字母、空格数,数字,和其他字符的个数. -
商若头孢: #include"stdio.h" void main() {char a[100] = {0}, i = 0;char n_C = 0, n_SP = 0, n_N = 0, n_O = 0; printf("Input String: \n\n");gets(a);while(a[i] != 0) {if ((a[i] >= 'A' && a[i] <= 'Z') ||(a[i] >= 'a' && a[i] <= 'z'))n_C++;else if (a[i] >= '0' && a[i] <= '...

西岗区13083087847: 1. 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数.(C语言) -
商若头孢: #include <stdio.h> int main(int argc, char *argv[]) {int i[4]={0,0,0,0};char a;while((a=getchar())!='\n'){if(a>='0'&&a<='9') i[0]++;//数字else if((a>='a'&&a<='z')||(a>='A'&&a<='Z')) i[1]++;//字母else if(a==' ') i[2]++;//空格else i[3]++;//其他字符}...

西岗区13083087847: c语言程序题:输入一行字符,分别统计并且按照顺序排列其中的数字和字母 -
商若头孢: #include "stdio.h" main() {char zifu[100],zimu[100],shuzi[100] ;int i=0;int zm=0,sz=0;//zimu和shuzi数组的索引值printf("请输入一行字符(数目小于100个)\n");//提示用户输入一行字符并换行do{scanf("%c",&zifu[i]);//将用户输入...

西岗区13083087847: c语言编写程序.输入一行字符,分别统计其中的英文字母,数字和其他字符的个数
商若头孢: #include <stdio.h> main() {int x=0,y=0,z=0; char ch; ch=getchar(); while(ch!='\n') { if(ch>=65&&ch<=90 || ch>=97&&ch<=122) x++; else if(ch>48&&ch<57) y++; else z++; ch=getchar(); } printf("英文字母有:%d个,数字有:%d个,其它字符有:%d个",x,y,z); }

西岗区13083087847: 用c语言写:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
商若头孢: #include "stdio.h" #include "string.h" int main() { char a[200]={}; int i,c_num,s_num,d_num,o_num; printf("Please input a string:"); gets(a); i=c_num=s_num=d_num=o_num=0; while(a[i]!='\n') { if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z') c_num...

西岗区13083087847: C语言编程,输入一行字符,分别统计出其中英文字母,空格,数字和其它字符的个数 -
商若头孢: 以下程序在win-tc下调试通过 /* 输入一行文字 找出其中大写字母小写字母空格数字及其他字符各有多少 */ # include "stdio.h"# include "conio.h" void main(void) { int upper=0,lower=0,digit=0,space=0,other=0,i=0; char *p,s[80]; printf("\nInput a...

西岗区13083087847: C语言:输入一行字符,分别统计其中英文字母、空格、数字和其他字符的个数 -
商若头孢: #include int main(){ int i,n,eng=0,spa=0,num=0,oth=0; char str[100]; gets(str);n=strlen(str); for(i=0;iif(str[i]>='a'&&str[i]='A'&&str[i]eng++; else if(str[i]==' ') spa++; else if(str[i]>='0'&&str[i]else oth++; printf("英文字母:%d\n空格:%d\n数字:%d\n其他字符:%d",eng,spa,num,oth); return 0; }

西岗区13083087847: c程序:输入一行字符,分别统计出其大小写英文字母、空格、数字和其他 -
商若头孢: #include<stdio.h> int main() {int letterCount = 0;//英文字母的个数int spaceCount = 0;//空格的个数int digitalCount = 0;//数字的个数int otherCount = 0;//其他字符的个数int a;while( (a=getchar()) != '\n'){if( (a>='A' && a<='Z') || (a>='a' && ...

西岗区13083087847: c语言编程:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数,用while语句~~谢谢 -
商若头孢: #include <stdio.h> int main() { int i=0, space=0, num=0, n=0, ch=0; char s[20]; printf("请输入一串字符 "); gets(s); while(s[i] != '\0') { if(s[i]==' ') space++; else if(s[i]<='9' && s[i]>='0') num++; else if(s[i]<='z' && s[i]>='a' || s[i]<='Z' && s[i]>='A') ch++;...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网