[問題] 矩陣切割問題
我的A矩陣沒辦法切割成四等份(2的倍數),
請問是哪邊出問題?
要怎麼思考比較好??
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 4 //N*N 矩陣
#define MAX 4 //分配亂數值0~3
void randV(int Matrix[N][N]); //分配矩陣內容亂數值 函式
void printArray(int Matrix[][]); //印出矩陣內容 函式
//void smallMatrix(Matrix_t A, int N,Matrix_t p11, Matrix_t p12, Matrix_t p21, Matrix_t p22);
//Matrix_t Matrix(int N);
int main() //主程式
{
int i,j,k;
int Matrix[N][N] = {0}; //初始化
srand(time(NULL)); //使用rand亂數
int A[N][N]={0}; // 宣告矩陣N*N大小,並初始化
int B[N][N]={0};
int C[N][N]={0};
printf(" 印出A矩陣\n");
randV(A); //使用Function呼叫A矩陣亂數值
printArray(A); //印出A矩陣內容
printf("------------------\n");
printf("------------------\n");
/*nt N1=N/2;
int a11[N1][N1]={0};
int a12[N1][N1]={0};
int a21[N1][N1]={0};
int a22[N1][N1]={0};
for (i=0; i<N/2; i++) //ead data from a[0][0] ... a[N1-1][N1-1]
for (j=0; j<N/2; j++)
a11[i][j] = A[i][j];
printf("%3d",a11[i][j]);
*/
printf("------------------\n");
printf(" 印出B矩陣\n");
randV(B); //使用Function呼叫B矩陣亂數值
printArray(B); //印出B矩陣內容
printf("------------------\n");
for(i=0;i<N;i++){ //A矩陣 * B矩陣
for(j=0;j<N;j++)
for(k=0;k<N;k++)
C[i][j]+=A[i][k]*B[k][j]; //得出C矩陣值
}
printf("------------------\n");
printf(" 印出C矩陣\n"); //印出C矩陣內容
printArray(C);
printf("\n");
system("pause");
return (0);
}
void randV(int Matrix[N][N]) //randV函式,分配矩陣內容亂數值
{
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++)
Matrix[i][j]=rand() % MAX;
}
}
void printArray(int Matrix[N][N]) //printArray函式,印出矩陣內容
{
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++)
printf("%4d",Matrix[i][j]);
printf("\n");
}
}
/*
Matrix_t Matrix(int N) // allocate an NxN matrix
{
int i; // loop-index
Matrix_t A = malloc(N*sizeof(double*));
if (A==NULL) NoSpace(); // call user's exception-handler
// else, p -> vector of pointers to rows of doubles to be allocated
for (i=0; i<N; i++)
{
A[i] = malloc(N*sizeof(double));
if (A[i]==NULL) NoSpace(); //call exception-handler
// else, obtained N columns of data for row i
}
return A;
}
void smallMatrix(Matrix_t A, int N,
Matrix_t p11, Matrix_t p12, Matrix_t p21, Matrix_t p22)
{
int N1 = N/2,
row,col; // loop-indexes
for (row=0; row<N1; row++) //read data from p[0][0] ... p[N1-1][N1-1]
for (col=0; col<N1; col++)
p11[row][col] = A[row][col];
for (row=0; row<N1; row++) //read data from p[0][N1] ... p[N1-1][N-1]
for (col=0; col<N1; col++)
p12[row][col] = A[row][col+N1];
for (row=0; row<N1; row++) // read data from p[N1][0] ... p[N-1][N1-1]
for (col=0; col<N1; col++)
p21[row][col] = A[row+N1][col];
for (row=0; row<N1; row++) // read data from p[N1][N1] ... p[N-1][N-1]
for (col=0; col<N1; col++)
p22[row][col] = A[row+N1][col+N1];
}
*/
框線框起來的部分就是一直出問題,沒辦法正常Run的部分
不知道改怎麼處理??
謝謝各位!
我想把A矩陣分解成p11 p12 p21 p22小矩陣。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.203.67
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章