int main() { // Game Board int myBoard[N][N]; // Game Board Pointer int* myBoardPointer = (int*)myBoard; // Initialize Array with Default Values initialize2DArray(myBoardPointer); randomizeBoard(myBoardPointer); std::cout << "Original Board:\n"; print2DArray(myBoardPointer); if (solveSudoku(myBoardPointer)) { std::cout << "Solved: \n"; print2DArray(myBoardPointer); } else { std::cout << "No Solution Exists: \n"; } return 1; }
int main( int argc, char* argv[]) { srand(time(0)); int** matrix = createAndRandomize2DIntArray(N,N); print2DArray(matrix,N,N); rotate90(matrix,N); cout << "\n*********************\n" << endl; print2DArray(matrix,N,N); del2DArray(matrix,N); return 0; }
int main() { /* * Test case * * Null matrix, 5x5 matrix */ int a[N][N] = {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}}; print2DArray(a); printf("\nRotation by line: \n"); // Rotate by line rotateMatrix(a); print2DArray(a); printf("\nRotation by number: \n"); // Rotate by line rotateMatrix2(a); print2DArray(a); return 0; }
/** lucrativePaths() A public method that prints out the results of Floyd's Algorithm. Uses a modified Dijkstra as a helper method. Input: none. Returns: void, though prints out a matrix of the results of Floyd. */ void Dungeon::lucrativePaths() //Floyd's Algorithm { int** resultMatrix = new int*[roomListSize]; uint i; for (i = 0; i < roomListSize; i++) { resultMatrix[i] = dijkstraReturn(i); } styledPrint("Lucrative Rooms Matrix", 0); print2DArray(resultMatrix, roomListSize); cout << endl; }
void testMake2DArray(void) { int **twoDimArray; int rowNum, colNum; int rowIdx, colIdx; printf("start testMake2DArray()\n"); rowNum = 5; colNum = 5; twoDimArray = make2DArray(rowNum, colNum); for(rowIdx = 0; rowIdx < rowNum; rowIdx++) for(colIdx = 0; colIdx < colNum; colIdx++) twoDimArray[rowIdx][colIdx] = rand() % 10; print2DArray(twoDimArray, rowNum, colNum); return; }
// // 테스트 함수: 동적 할당된 2차원 배열 메모리의 함수 전달 및 출력 // void testMake2DArray(void) { int **twoDimArray; int rowNum, colNum; int rowIdx, colIdx; printf("start testMake2DArray()\n"); // 행과 열의 개수 지정 rowNum = 5; colNum = 5; // 지정된 크기의 matrix 메모리 생성 twoDimArray = make2DArray(rowNum, colNum); // matrix의 각 원소에 임의의 값 저장 for(rowIdx = 0; rowIdx < rowNum; rowIdx++) for(colIdx = 0; colIdx < colNum; colIdx++) twoDimArray[rowIdx][colIdx] = rand() % 10; print2DArray(twoDimArray, rowNum, colNum); return; }
/* The timing information for ith step consists of: * globalTime[i][0]: cumulative time from 0 seconds; * globalTime[i][1]: displacement ratios??? * globalTime[i][2]: the time increment \Delta t * for the ith step * It would be very convenient to examine this data * graphically. But instead of just dumping the array * through the print2DArray() function, we can do * better: format the output for Matlab input. */ void writeTimeInfo(Analysisdata * ad) { /* Kludge. Output file formats will eventually have * their own struct. */ int matlab = 1; char * matlabcomment = "%% "; char * gnuplotcomment = "## "; char * comment; double ** globalTime = ad->globalTime; int m = ad->globaltimesize1; int n = ad->globaltimesize2; if (matlab == 1) comment = matlabcomment; else comment = gnuplotcomment; /* Here is a reason to have nice wrapper functions * around ordinarily pedestrian array output. Since * post-processing is traditionally a major PITA, we * can use Matlab (or octave) to slurp up named arrays * and plot large arrays. Consequently, we need to * name the arrays, and it is always helpful to add a few * comments in the matlab script explaining the data in * the arrays. */ /* Matlab comments are preceded by a "%" sign. We need * two because the C compiler uses a single % sign for * formatting data. */ fprintf(fp.timefile,"%s Global time data.\n" "%s globaltime:\n" "%s col 1: cumulative time\n" "%s col 2: displacement ratio??\n" "%s col 3: time step \\Delta t\n\n", comment, comment, comment, comment, comment); if (matlab == 1) fprintf(fp.timefile,"globaltime = ["); /* Now, for another reason to have wrapper functions, * consider this: The `globalTime' array is not * initialized when it is allocated. Then, no * values are stored in the zero position of the * "2d" dimension, but the first dimension of the * array DOES index from zero. So, what we do is * the following... */ globalTime[0][0] = 0; globalTime[0][1] = 0; globalTime[0][2] = 0; /* Otherwise, the uninitialized contents of the second * dim leading may contain spurious values, on the order * of say -10^{66}. Now, pass it to the function which * actually writes it to a file. */ print2DArray(globalTime, m,n,fp.timefile, ""); /* And add the trailing bracket for the Matlab * matrix notation: */ fprintf(fp.timefile,"];\n\n"); /* So, when the analysis concludes, these data stored in * the globalTime array are formatted for direct Matlab * input in an appropriate `m' file. Spiffy, no? */ } /* close writeTimeInfo() */