gpt4 book ai didi

c - 数组简介

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:33 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
when do we need to pass the size of array as a parameter

所以我刚开始使用数组,我需要创建 3 个函数来让我学习。

int sumarray(int a[], int n);

// a is an array of n elements
// sumarray must return the sum of the elements
// you may assume the result is in the range
// [-2^-31, 2^31-1]

int maxarraypos(int a[], int n);

// a is an array of n elements
// maxarraypos must return the position of
// the first occurrence of the maximum
// value in a
// if there is no such value, must return 0

bool lexlt(int a[], int n, int b[], int m);

// lexicographic "less than" between an array
// a of length n and an array b of length m
// returns true if a comes before b in
// lexicographic order; false otherwise

我将如何创建这些函数?

对于 sumarray,我很困惑,因为数组存储的内容在一定长度内。为什么需要第二个参数 n

还有我如何测试一个使用数组的函数?我在想 sumarray([3], 3) ..对吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com