C语言程序实现,统计字符串里面各个字符的个数在总字符个数中的比例,并打印输出。...

 1 #include<stdio.h>
 2 int main()
 3 {
 4     char *ppp= "aaassadddeeds";
 5     char c[255] = {0};//存放字符
 6     uint32 ccnt[255] = { 0 };//存放字符对应的个数
 7     char *t = NULL;
 8     t = ppp;
 9     uint32 index_i = 0;
10     uint32 count = 0;//总字符的个数
11     uint32 cnt = 0;//字符的种类数
12     while (*t != '\0')
13     {
14              /*在存储区域内之前出现过*/
15         for (index_i = 0; index_i < cnt; index_i++)
16         {
17             if (c[index_i] == *t)
18             {
19                 ccnt[index_i]++;
20                 break;
21             }
22         }
23            /*在存储区域内第一次出现*/
24         if (index_i >= cnt)
25         {
26             c[cnt++] = *t;
27             ccnt[index_i]++;
28 
29         }
30         t++;
31         count++;
32     }
33     printf("%d\n", debug);
34     printf("%d\n", count);
35     for (index_i = 0; index_i < cnt; index_i++)
36     {
37         printf("%c %.2f%%\n", c[index_i], float((float)ccnt[index_i] / count)*100);
38     }
39     return 0;
40 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值