Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define HEIGHT 5
- #define WIDTH 5
- int board[HEIGHT][WIDTH];
- int i, j;
- int chessBoard()
- {
- srand(time(NULL));
- for ( i = 0; i < HEIGHT; ++i)
- {
- for ( j = 0; j < WIDTH; ++j)
- {
- int randRes = rand() % 4;
- if (randRes == 1)
- {
- board[i][j] = 1;
- }
- else
- {
- board[i][j] = 0;
- }
- printf("%5d", board[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- }
- int routes(int x, int y)
- {
- if (board[i][j] == 0 && x == 0 && y == 0)
- {
- return 0;
- }
- else if (board[i][j] == 1 && x == 0 || y == 0)
- {
- return 0;
- }
- else if (x == 0 ^ y == 0)
- {
- return 1;
- }
- else
- {
- return routes(x, y - 1) + routes(x - 1, y);
- }
- }
- int main()
- {
- chessBoard();
- const int sizeX = 5;
- const int sizeY = 5;
- for (int y = 0; y < sizeY; ++y)
- {
- for (int x = 0; x < sizeX; ++x)
- {
- printf("%5d", routes(x, y));
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement