#include <stdio.h>
int main() {
int H_SIZE=32; /*length of each code word: you can change. */
int n,r1,c1,i,j;
int hadamard_matrix[32][32]={1,}; /* Initialise 1x1 matrix */
for (r1=1;r1<H_SIZE; r1*=2){
for (i=0;i<r1;i++){ /* loop#1: Copying the code matrix itself below for new code matrix */
for (j=0;j<r1; j++){
hadamard_matrix[i+r1][j]=hadamard_matrix[i][j];
}
}
for (i=0; i<r1;i++){/* Loop#2: Copying the code matrix on right to itself for new matrix */
for (j=0; j<r1;j++){
hadamard_matrix[i][j+r1]=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<r1;j++){
hadamard_matrix[i+r1][j+r1]=1-hadamard_matrix[i][j];
}
}
}
for(i=0;i<H_SIZE;i+=1) {
for(j=0;j<H_SIZE;j+=1) {
printf("%2d", hadamard_matrix[i][j]);
}
printf("\n");
}
return 0;
}
===========================================================
#include <stdio.h>
#include <stdlib.h>
void create_hadamard_matrix(char **h, int N) {
int i, j, r1;
for (r1=1;r1<N; r1+=r1){
for (i=0;i<r1;i+=1){ /* loop#1: Copying the code matrix itself below for new code matrix */
for (j=0;j<r1; j+=1){
h[i+r1][j]=h[i][j];
}
}
for (i=0; i<r1;i+=1){/* Loop#2: Copying the code matrix on right to itself for new matrix */
for (j=0; j<r1;j+=1){
h[i][j+r1]=h[i][j];
}
}
for (i=0;i<r1;i+=1){/* Loop#3: Copying cojugate of code matrix for complentary diagonal part */
for (j=0;j<r1;j+=1){
h[i+r1][j+r1]='*'+'.'-h[i][j];
}
}
}
}
int main() {
char **hadamard;
int i, j, n;
printf("크기: ");
scanf("%d", &n);
hadamard=(char**)malloc(n*sizeof(int));
for(i=0;i<n;i+=1) {
hadamard[i]=(char*)calloc(1,n);
}
hadamard[0][0]='*';
create_hadamard_matrix(hadamard, n);
for(i=0;i<n;i+=1) {
for(j=0;j<n;j+=1) {
printf("%c", hadamard[i][j]);
}
printf("\n");
}
return 0;
}
'c·c++ > c 프로그래밍' 카테고리의 다른 글
주민번호 판별 (0) | 2013.09.18 |
---|---|
3x3 행렬식(determinant) 구하기 (0) | 2013.09.15 |
두수의 비교 (0) | 2013.09.13 |
Cramer공식을 이용한 연립방정식풀기 (0) | 2013.09.13 |
자리수 제한없이 피보나치수열 구하기 (0) | 2013.09.13 |