与数组相关的函数 [英] Array-related Functions

查看:78
本文介绍了与数组相关的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为showArray的函数(int ar [],int numElements和int numPerLine)

我在创建函数方面遇到了一些问题,以便调用者可以调用它。到目前为止我有这个:


/ ******************************

函数名称:void showArray(int ar [],int numElements,int numPerLine)



****** ************************ /

void showArray(int ar [],int numElements,int numPerLine)

{

int i;`



while(numElements< 200)

{

i = ar [0];

cout<< i;

i ++;

}

if(numPerLine * = 2)

cout<< endl;


将传递一个包含200个元素的数组。在主要我有一个元素数量的符号常量,但不知道通过其他两个参数是什么。有什么建议?!?!我知道功能也编码不正确!谢谢

解决方案

顺便说一下,函数需要显示数组的元素,第三个参数指定的每行几个项目。 seconds参数告诉函数数组中有多少项,因此它知道停止的位置。当已打印的项目数是numPerLines的倍数时,我需要输出换行符。也许%运营商?谢谢


你好brady,


你还没有为你的while循环定义一个好的条件。你无法预测

你的数组将有200个元素。为什么不使用类似的东西:

展开 | 选择 | Wrap < span class =codeDivider> | 行号


Hello Savage,

感谢您的回复!这比我拥有的更有意义。对于柜台,我可以在递增后立即放置吗?然后可能有一个决定声明。我是C ++的新手,所以它有点令人困惑。


你好brady,


你还没有定义一个你的while循环的良好条件。你无法预测

您的数组将有200个元素。为什么不使用类似的东西:

展开 | 选择 | Wrap | 行号< /跨度>

i have a function called showArray(int ar[], int numElements, and int numPerLine)
i am having some issues with creating the function properly so that the caller can call it. so far i have this:

/******************************
Function Name: void showArray(int ar[], int numElements, int numPerLine)



******************************/
void showArray(int ar[], int numElements, int numPerLine)
{
int i;`


while(numElements < 200)
{
i = ar[0];
cout << i;
i++;
}
if(numPerLine *= 2)
cout << endl;


an array will be passed through which has 200 elements. in main i have a symbolic const for the number of elements but dont know what passes through the other two arguments. any suggestions?!?! i know the function is coded incorrectly also! Thanks

解决方案

By the way, the function needs to display the elements of the array, several item per line as specified by the third argument. The seconds argument tells the function how many items are in the array, so it knows where to stop. i need to output a newline character when the number of items slready printed is a multiple of numPerLines. maybe the % operator? Thanks


Hi brady,

You have not defined a good condition for your while loop.You cannot predict
that your array will have 200 elements.Why not use instead something like:

Expand|Select|Wrap|Line Numbers


Hello Savage,
Thanks for the reply! That makes a lot more sense then what i had. For the counter, can i just place that right after incrementing i? then maybe have a decision statement. im new with C++ so its a bit confusing.

Hi brady,

You have not defined a good condition for your while loop.You cannot predict
that your array will have 200 elements.Why not use instead something like:

Expand|Select|Wrap|Line Numbers


这篇关于与数组相关的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆