Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <math.h>
- #define size 10
- #define rows 5
- #define cols 5
- void route(int arr[rows][cols]) {
- int i=0,j=0;
- while(i<rows && j < cols){
- if(i==rows-1 && j == cols-1)
- break;
- else if(i==rows-1){
- printf("right ");
- j++;
- }
- else if(j==cols-1){
- printf("down ");
- i++;
- }
- else if(arr[i+1][j]<arr[i][j+1]){
- printf("down ");
- i++;
- }
- else{
- printf("right ");
- j++;
- }
- }
- }
- int main() {
- int arr[rows][cols];
- srand(time(NULL));
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- arr[i][j] = (0 + rand() % (9 - 0 + 1));
- }
- }
- puts("arr");
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- printf("%d ", arr[i][j]);
- }
- puts("");
- }
- route(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement