c - 我想为 hadamard 矩阵执行此 c 代码。并且想要 hadamard 矩阵的新代码(如果有)

标签 c

我正在尝试为 Hadamard matrix 编译此代码一代。谁能告诉我为什么这段代码没有被执行吗?

#include <stdio.h>
#include <math.h>
#include <conio.h>

main() {
int H_SIZE=32;  /*length of each code word: you can change. */
int n,r1,c1,i,j;
int hadamard_matrix[2][2]={{1,1},{1,0}}; /* Initialise 1x1 matrix */
for (r1=0;n<H_SIZE; r1*=2){
for(c1=0; c1<H_SIZE;c1*=2){
    while (r1<H_SIZE){
        for (i=0;i<r1;i++){ /* loop#1: Copying the code matrix itself    below for new code matrix */
            for (j=0;j<c1; j++){
            hadamard_matrix[i+r1][j]=hadamard_matrix[i][j];
        }
        }
        for (j=0; j<c1;j++){/* Loop#2: Copying the code matrix on right to itself for new matrix */
            for (i=0; i<r1;i++){
            hadamard_matrix[i][j+c1]=hadamard_matrix[i][j];
            }
        }
        for (i=0;i<r1;i++){/* Loop#3: Copying cojugate of code matrix for complentary diagonal part */
            for (j=0;j<c1;j++){
                hadamard_matrix[i+r1][j+c1]=hadamard_matrix[i][j];}}  
      }        
    }
   }
printf("%d\t", hadamard_matrix);
}

最佳答案

首先:通过编译器运行它,我打赌它不会编译。启用编译器警告。

其次:

main() {

那是行不通的。做:

void main(void) {

第三:

n<H_SIZE

这应该是做什么的?您可能想输入 r1。请注意,您的 n 从未初始化,也从未在代码中的其他任何地方使用

第四:

printf("%d\t", hadamard_matrix);

这不是打印矩阵的工作原理。

你似乎还缺少一个右大括号。

关于c - 我想为 hadamard 矩阵执行此 c 代码。并且想要 hadamard 矩阵的新代码(如果有),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030921/

相关文章:

c - 这里映射一行 URL WLAN 地理位置

c - 需要帮助了解如何在高级逆波兰表示法程序中使用堆栈和二叉搜索树

C:使用 scanf() 函数而不是 gets

c - Automake + 库工具 : pattern rule for per-object CFLAGS?

c - 如何使用 execvp() 执行命令

c - sprintf 中的编码

c - 在 C 中初始化多维数组

c - 为什么使用 MSVC 可以工作,而使用 GNU 会出现错误 : array type has incomplete element type using struct

c - 如果键盘中断作为输入,执行在哪里停止?

c - 在 C 中使用字母 ñ