所以我每天都面临脱发的问题,因为我第一年的任务需要这个子任务。
在程序的初始化阶段,我需要在坐标 [5][5] / 即板的中心处的数字周围打印一个“框”。
“盒子”由“ | ”组成,覆盖两侧,“ _ ”在坐标 [5][5]处的数字的顶部和底部。
当我执行这个程序时,板子显示但“盒子”没有。为什么会这样??
这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//FUNCTION: Draw the Board
int drawBoard()
{
//Declare array size
int board[9][9];
//initialize variables
int rows, columns, randomNumber, flag;
//random number seed generator
srand(time(NULL));
for ( rows = 0 ; rows < 9 ; rows++ )
{
for ( columns = 0 ; columns < 9 ; columns++ )
{
flag = 0;
do
{
//generate random numbers from 2 - 8
randomNumber = rand() %7 + 2;
board[rows][columns] = randomNumber;
//Display the 'box' if rows and columns == 5 / i.e - board[5][5]
if ( rows == 5 && columns == 5 )
{ //Checks for 2 adjacent numbers
if ( board[rows][columns] == board[rows - 1][columns] || board[rows][columns] == board[rows][columns - 1] )
{
flag = 0;
continue;
}
else
{
flag = 1;
//Print 'box'
marker( rows, columns );
}
}
//Checks for 2 adjacent numbers.
if ( board[rows][columns] == board[rows - 1][columns] || board[rows][columns] == board[rows][columns - 1] )
{
flag = 0;
continue;
}
else
//Prints the correct board
{
flag = 1;
printf( " %d ", board[rows][columns] );
}
} while ( flag == 0 ); //end outer do-while
}//end inner for-loop
printf("\n\n");
}//end outer for-loop
}//end FUNCTION drawBoard
//FUNCTION: Mark the surrounding of the number with "|" and "_" at board[5][5]
void marker( int x, int y, int** board )
{
board[x][y-1] == "\n _ ";
board[x][y+1] == "\n _ ";
board[x-1][y] == " |";
board[x+1][y] == "| ";
}
int main()
{
drawBoard();
}
德州仪器