网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

C求数字字符串中各个数字出现的次数

时间:2024-10-14 02:03:48

1、打开Dev-C++。

C求数字字符串中各个数字出现的次数

2、#include<stdio.h>#include<string.h>void main() {}

C求数字字符串中各个数字出现的次数

3、#include<stdio.h>void main() { char a[100]; int acount[10]={0},i; gets(a像粜杵泳); for(i=0; a[i]!='\0'; i++) { acount[a[i]-'0']++; } for(i=0; i<10; i++) { printf("%d=>%d\n",i,acount[i]); }}

C求数字字符串中各个数字出现的次数

4、给代码添加注释。#include<stdio.h>void main() { //声明字符串数组 艘早祓胂char a[100]; //声明保存各个数字出现次数的数组 int acount[10]={0},i; gets(a); //遍历字符串数组,统计各个数字出现的次数 for(i=0; a[i]!='\0'; i++) { acount[a[i]-'0']++; } //输出各个数字以及出现的个数 for(i=0; i<10; i++) { printf("%d=>%d\n",i,acount[i]); }}

C求数字字符串中各个数字出现的次数

5、运行结果,如下所示。

C求数字字符串中各个数字出现的次数
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com