c语言中统计字符串中数字出现的次数。

1、

#include <stdio.h>

void count(char x[], int y[])
{
    int i = 0;
    while(x[i])
    {
        if(x[i] >= '0' && x[i] <= '9')
            y[x[i] - '0']++;
        i++;
    }
}

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    int a[10] = {0};
    count(str, a);
    int i;
    for(i = 0; i < 10; i++)
    {
        printf("'%d' : %d\n", i, a[i]); 
    }
    return 0;
}

c语言中统计字符串中数字出现的次数

 

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-22
  • 2021-07-12
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案