小编emc*_*kic的帖子

编写一个函数,对于给定的非负整数 n,以数字形式返回 9 出现的次数

我无法解决这个问题,几天来我一直在努力解决这个问题。这是问题的全文:

编写一个函数,对于给定的非负 int ,以数字形式n返回 出现的次数,但 a紧邻其左侧的另一个会计数为双倍,因此结果为 4。9999912349

该问题有两部分:a) 和 b)。

a) 部分要求使用递归来解决该问题,并且

b) 部分需要迭代。

我主要在递归问题上遇到麻烦。这是我的 a) 部分的代码:

#include <stdio.h>
#include <stdlib.h>

/* Write a function that for a given a non-negative int n, computes the count of the 
occurrences of 9 as a digit, except
that an 9 with another 9 immediately to its left counts double, so 9914329 yields 4. */

int recursiveNines(int mynumber) {
    int counter = 0;
    if (mynumber = 0) …
Run Code Online (Sandbox Code Playgroud)

c iteration recursion function

1
推荐指数
1
解决办法
306
查看次数

标签 统计

c ×1

function ×1

iteration ×1

recursion ×1