Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入带有递归函数且无循环的scanf数组(.c)_C - Fatal编程技术网

输入带有递归函数且无循环的scanf数组(.c)

输入带有递归函数且无循环的scanf数组(.c),c,C,用户给我数组的大小,我用函数“MALLOC”分配内存分配,只用递归得到数组的输入,没有循环 我不知道如何使用递归函数创建“循环” 我希望能得到帮助 谢谢。这不是递归的好用法-在这种情况下循环更“自然”-但其思想是这样一个函数: void getInput(int howMany) { if (howMany == 0) return; // get user input getInput(howMany-1); } 因为这看起来像是家庭作业,所以我将给出一个面向家庭作业的答

用户给我数组的大小,我用函数“MALLOC”分配内存分配,只用递归得到数组的输入,没有循环

我不知道如何使用递归函数创建“循环”

我希望能得到帮助


谢谢。

这不是递归的好用法-在这种情况下循环更“自然”-但其思想是这样一个函数:

void getInput(int howMany)
{
  if (howMany == 0)
    return;
  // get user input
  getInput(howMany-1);
}

因为这看起来像是家庭作业,所以我将给出一个面向家庭作业的答案——用伪代码

define loop(array, index)
    if index == 0
        return array
    array[index] = get input from user
    loop (array, index-1)
循环(数组,数组大小)
调用它

我想回应Mat的观点,即这不是递归的好用法

更新

由于您希望使用
scanf(3)
来读取输入,因此我将给出一个关于如何使用它的更有力的提示。在上面,我写道:

    array[index] = get input from user
您可以使用以下
scanf(3)
call编写这行代码:

scanf("%d", &array[index]);

这将在
数组[index]
位置中存储一个十进制整数--
&
返回数组插槽的地址,而不是评估数组订阅。

很难理解您的要求,您能澄清一下吗?我需要从数组的用户大小输入并创建此数组的分配内存。并将值扫描到此数组。我写了这个函数,但它不起作用
void-getss(int-array[],int-size)
{int-counter=0;if(size==0)返回;if(反驳)我同意你的观点,但这是我讲师的要求。但我需要创建一个memorey Alloction,我不需要发送函数的点?我需要数组中用户值的扫描输入。我不明白没有循环我如何扫描输入。+1你在这方面付出的努力比OP应得的要多。