C用数学函数初始化三维数组? [英] C initializing three dimensional array with math function?

查看:48
本文介绍了C用数学函数初始化三维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看第一年计算机科学课程的过去考试,我对一个问题感到困惑.我不知道它在问什么.我不是要有人为我做这件事,但如果有人能帮助我理解这个问题要我做什么,我将不胜感激.

I am looking at past exams for a first year computer science course and I am confused about one question. I have no idea what it's asking. I am not asking someone to do it for me, but I would appreciate if someone could help me understand what the question wants me to do.

根据下面的规范,编写一个完整的C程序来分配,初始化,打印和取消分配int类型变量的三维数组.三个数组维度x,y和z的大小分别为3、2和4.

Write a complete C program to allocate, initialize, print, and de-allocate a three-dimensional array of int type variables, according to the specifications below. The sizes of the three array dimensions x, y, and z, are 3, 2, and 4, respectively.

应根据以下函数初始化数组元素

The array elements should be initialized according to the following function

f(x,y,z)= 5x + 6y + 7z

f(x,y,z) = 5x + 6y + 7z

这意味着您的初始化代码将如下所示:

Which means your initialization code will look like this:

myArray [x] [y] [z] = 5 * x + 6 * y + 7 * z;

myArray[x][y][z] = 5 * x + 6 * y + 7 * z;

以下是一些示例输出:

0 7 14 21
6 13 20 27

5 12 19 26
11 18 25 32

10 17 24 31
16 23 30 37

首先,我不明白问题在问什么.我看到的唯一模式是每个值都是先验值+ 7.

Firstly, I do not understand what the question is asking. The only pattern I see is that each value is the prior value + 7.

Facepalm.谢谢安迪.我以为那完全是另外一回事.

Facepalm. Thanks Andy. I thought it was totally something else.

推荐答案

作业中没有任何问题.有以下要求

There is no any question in the assignment. There is the following request

编写一个完整的C程序来分配,初始化,打印和根据以下说明取消分配int类型变量的三维数组符合以下规格

Write a complete C program to allocate, initialize, print, and de-allocate a three-dimensional array of int type variables, according to the specifications below

此声明中有哪些不清楚之处?

What is not clear in this statement?

还有一个示例,说明如何初始化数组的每个元素

And there is an example how each element of the array shall be initialized

myArray[x][y][z] = 5 * x + 6 * y + 7 * z;

因此,您需要为数组的每个维度编写三个嵌套循环.

So you need to write three nested loops each loop for each dimension of the array.

例如

for ( int x = 0; x < 3; x++ )
{
   for ( int y = 0; y < 2; y++ )
   {
      for ( int z = 0; z < 4; z++ )
      {
         myArray[x][y][z] = 5 * x + 6 * y + 7 * z;
      }
   }
}

这篇关于C用数学函数初始化三维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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