返回每个元素限制数组的所有可能性

发布于 2025-01-27 08:57:49 字数 325 浏览 3 评论 0原文

我想在C中创建一个函数,该函数将参数作为参数作为一个数组,其中每个元素给出范围(从0到存储在数组索引中的数字),我想返回所有可能性

一个例子是,

int elements[2] = [2,4]
int *combinations = combinations(&elements, 2) // 2 being the size of elements

这将给出:

0 0
1 0
0 1
0 2
0 3
1 1
1 2
1 3

我应该如何编码它,以返回一系列数组,以便我可以测试所有组合

I would like to create a function in c that takes in an argument that takes in as an argument an array where for each element it gives the range (from 0 to the number stored at the array index), I would like to return all possibilities

an example would be

int elements[2] = [2,4]
int *combinations = combinations(&elements, 2) // 2 being the size of elements

this would give something along the lines of:

0 0
1 0
0 1
0 2
0 3
1 1
1 2
1 3

I've been stuck as to how I should code it, in order to return an array of arrays so that I can test all combinations possible

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文