c语言输入十个英文国名,c语言程式设计 在主函式输入10个字元,用子函式求出共输入几个英文字元,几个数字字元,几个符号%...

c语言程式设计 在主函式输入10个字元,用子函式求出共输入几个英文字元,几个数字字元,几个符号%以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

784495cd6cb3eaffc42da62fe6ef664b.png

c语言程式设计 在主函式输入10个字元,用子函式求出共输入几个英文字元,几个数字字元,几个符号%

#include

#include

int main(void)

{

int ch,icountE=0,icountD=0;

printf("请输入10个字元\n");

while((ch=getchar())!=EOF)

{

if(ch>'a'&&ch'A'&&ch

{

icountE++;

}

else if(ch>'0'&&ch

{

icountD++;

}

}

printf("输入英文字元个数为%d,输入数字个数为%d",icountE,icountD);

system("PAUSE");

return 0;

}

java新手 求个“输入10个字元,统计其中英文字母、数字字元和其他字元的个数。”

import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); System.out.println(str); int alphaNum=0,digitNum=0,otherNum=0; for(char c:str.toCharArray()){ if(Character.isDigit(c)) digitNum++; else if(Character.isAlphabetic(c)){ alphaNum++; }else{ otherNum++; } } System.out.println("alphaNum="+alphaNum+",digitNum="+digitNum+",otherNum="+otherNum); }}

C语言程式设计 输入字元a的程式编写

#include

void main()

{

char c;

printf(“input a”\n);

scanf("%c",&c);

}

统计字元:输入15个字元,统计其中英文字母、空格或回车、数字字元和其他字元的个数。编写程式

#include void main(){ int letter, space, digit, other; char ch; letter = space = digit = other = 0; while ((ch = getchar ()) != '\n') { if (ch>='a' && ch <= 'z' || ch>='A'&&ch<='Z') letter++; else if (ch>='0' && ch <='9') digit++; else if (ch == ' ') space++; else other++; } printf ("字母:%d\n", letter); printf ("空格:%d\n", space); printf ("数字:%d\n", digit); printf ("其它字元:%d\n", other);}

程式设计输入一行数字字元用阵列元素作为记数器来统计每个数字字元的个数

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

String s = Console.ReadLine();

char[] c = s.ToCharArray();

int[] ii = new int[10] {0,0,0,0,0,0,0,0,0,0};

for (int i = 0; i < c.Length; i++)

{

switch (c[i])

{

case '0': ii[0]++; break;

case '1': ii[1]++; break;

case '2': ii[2]++; break;

case '3': ii[3]++; break;

case '4': ii[4]++; break;

case '5': ii[5]++; break;

case '6': ii[6]++; break;

case '7': ii[7]++; break;

case '8': ii[8]++; break;

case '9': ii[9]++; break;

default: break;

}

}

for (int i = 0; i <= 9; i++)

{

Console.WriteLine(i + "有" + ii[i] + "个!");

}

Console.Read();

}

}

}

编写有函式的c语言程式,通过指标操作,统计一个字串中数字字元的个数

int tongji(char *p){ int i,sum=0; for(i=0;p[i]!=0;i++){ if(p[i]>='0'&&p[i]<='9')sum++; } return sum;}int main(){ char str[30]; scanf("%s",str); printf("%d",tongji(str));}

c语言程式设计 使用函式呼叫实现两个字串得连线

#include

char *catstr(char *a,char *b)

{

char *p=a,*q=b;

while(*p) p++;

while(*q)*p++=*q++;

*p='\0';

return a;

}

void main()

{

char s1[50]="abcdef";

char s2[]="12345678890";

printf("s1+s2=%s\n",catstr(s1,s2));

}

从键盘输入20个字元到阵列,统计其中的英文字元空格字元数字字元及其

#include

void main()

{ char a[256];

int i,n1,n2,n3,n4;

gets(a);

for ( i=n1=n2=n3=n40;i<20;i++ )

if ( a[i]==' ' ) n1++;

else if ( (a[i]>='0')&&(a[i]<='9') ) n2++;

else if ( (a[i]>='a' && a[i]<='z')||(a[i]>='A' && a[i]<='Z') ) n3++;

else n4++;

printf("英文字元个数%d,空格数%d,数字字元个数%d,其他字元%d\n",n3,n1,n2,n4);

}

输入一个以回车符结束的字串(少于80个字元),统计其中数字字元的个数。C语言

#include

#include

int main()

{

char str[100];

int len,i,sum=0;

gets(str);

len=strlen(str);

for(i=0;i

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

sum++;

printf("%d\n",sum);

return 0;

}

输入一字串,统计其中的英文字元、数字字元、空格及其它字元的个数。

void main(){

char c[80],*p;

int nchar=0,nspc=0,nnum=0,nword=0,ntotal=0,nother=0;

gets(c);

p=c;

while (*p!='\0'){

if ((*p<='z' && *p>='a') || (*p<='Z' && *p>='A'))

nchar++;

else if (*p<='9' && *p>='0') nnum++;

else if (*p==' ')

nspc++;

else nother++;

ntotal++;

p++;

}

printf("有字元%d个,有空格%d个,有数字%d个,有其他字元%d个。\n",nchar,nspc,nnum,nother);

}

分页:

1

23

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值