C 编程 : Sum of third upper anti-diagonal a squared matrix , 急需帮助,请

标签 c matrix

我正在上一门 C 编程短期类(class),最近我一直忙于其他类(class),并帮助我的麻烦准备他的婚礼(因为我是他的伴郎),所以我已经落后了,需要帮助。任何对这个简短作业的帮助将不胜感激,因为我根本不熟悉矩阵及其在几天内到期。

分配给方阵第三个上反对角线的和。

我已获得以下信息:

矩阵应该是大小为 N 的方整数矩阵。在此赋值中,矩阵将被存储 在一维内存块中。您必须在概念性二维矩阵寻址和 使用指针算术进行一维 block 寻址。

关于随机数的注意事项: rand() 函数返回范围内的伪随机整数序列中的下一个整数 [0,RAND_MAX]。 RAND_MAX 是一个非常大的数字,并且因系统而异。为了得到一个 [min, max] 范围内的整数:

(int)((min)+rand()/(RAND_MAX+1.0) * ((max)-(min)+1))

srand(SEED) 用于设置 rand 的种子。如果使用相同的种子值调用 srand() ,则 重复伪随机数序列。每次获取不同的随机数 程序运行使用time(NULL)作为种子。 Rand 在 stdlib.h 中,需要包含它。

该程序的结构应如下。

#define N 32 // Matrix size

#define MYSEED 1234 // Last 4 digits of your student number.

int *initialise( )        // Allocate memory for the matrix using malloc
                           // Initialise the matrix with random integers x, 1≤ x ≤ 9
                           // Use 'MYSEED' as the seed in the random generator.
                           // Return a pointer to the matrix

void print_matrix(int *)      // Print matrix on screen

int compute_diagonal(int *)   // Compute your required calculation using pointer arithmetic.
                              // (square bracket [ ] array indexes shouldn't be used)
                              // Return the solution.

void finalise(int *)          //free the allocated memory.

int main()                    // The main function should print the solution to screen.

最佳答案

无需为您做家庭作业,这里有一个提示:

创建一个从矩阵中抽象存储和检索值的函数。其中一个签名应该看起来很像这样:

int retrieve(int* matrix, int row, int col);

关于C 编程 : Sum of third upper anti-diagonal a squared matrix , 急需帮助,请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568421/

相关文章:

python - 如何求解未知矩阵的矩阵方程?

Java 矩阵 - 转置和求和

python - python中的复杂对称矩阵

matlab - 基于第一行值扩展矩阵 (MATLAB)

python - 用 C 扩展 Python、numpy——代码还好吗?

c - 将 void 分配给双指针

c - 在 C 中释放内存时应考虑哪些主要事项?

c - 如何在 C 程序中将结构映射到节属性?

c - 在用户输入旁边打印输出

matlab - MATLAB 中的笛卡尔积