Question #278071

Journey to Another Dimension

by CodeChum Admin

Somehow, in some way, you find yourself in a dimension within a dimension. Traverse the dimension and look for the exit!

Instructions:


Instructions

  1. Go through the 2D array and search for the array index containing the int value named “exit”.
  2. Print the indices with one space in between the column and row index.

Input

A single int input

1

Output

2 int outputs separated by a space

0·0




---------------to fill up code--------------------


#include<stdio.h>


int main() {

    int exit;

    scanf("%d", &exit);

    

    int col_row[5][5] = {{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}};

    

    

}


Expert's answer

#include<stdio.h>

int main() 
{
  int exit;
  scanf("%d", &exit);

  int col_row[5][5] = {
      { 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 }
  };
  
  for (int i = 0; i < 5; i = i + 1) {
    for (int j = 0; j < 5; j = j + 1) {
      if (col_row[i][j] == exit) {
        printf("%d %d\n", i, j);
        return 0;
      }
    }
  }  
  return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS