结合数组和递归的C程序

结合数组和递归的C程序

本文介绍了结合数组和递归的C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于给定数字'n',我们在表格周围放置1到n的数字,并开始删除从2开始的数字,如下所示:

=========== =示例===========

n = 6

1 2 3 4 5 6 - >我们删除了2,4,6

现在我们有:1 _ 3 _ 5 _

然后如果我们想象它们在6之后我们必须删除2但是因为它已删除我们删除2之后的数字是3.因为他们在3之后我们要删除1(5之后的数字)。最后我们得到5号就是答案



我尝试了什么:



i不能将这个过程转换成代码,特别是在数组末尾我们必须从数组的开头开始的部分,特别是递归函数

for a given number 'n' we put numbers form 1 to n around a table and start deleting the numbers starting from 2 like this:
============EXAMPLE===========
n=6
1 2 3 4 5 6 --> we delete 2,4,6
now we have: 1 _ 3 _ 5 _
then if we imagine them around a table after 6 we gotta delete 2 but since it has been deleted we delete the number after 2 which is 3. since they're around a table after 3 we gotta delete 1 (the number after 5). at the end we get to the number 5 which is the answer

What I have tried:

i cant translate this process into code especially the part that at the end of the array we gotta start from the beginning of the array especially the recursive function

推荐答案



int* shortenArray(const int *array, int cnt);


这篇关于结合数组和递归的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:40