Find element inside a two dimensional array : Array Two Dimension « Data Type « C / ANSI-C






Find element inside a two dimensional array

  
#include <stdio.h>

int main(void)
{
  int maps[5][2] = {
    1, 14,
    2, 28,
    3, 19,
    4, 8,
    5, 15
  };

  int key;
  int i;

  printf("Enter the key: ");
  scanf("%d", &key);

  /* look it up in the table */
  for(i = 0; i < 5; i++)
    if(key == maps[ i ][ 0 ]) {
      printf("Key %d value pair to %d.\n",
             maps[ i ][ 1 ], key);
      break;
    }

  /* report error if not found */
  if(i == 5) 
      printf("value not listed.\n");

  return 0;
}

           
       








Related examples in the same category

1.Two-Dimensional arrays
2.Getting the values in a two-dimensional array
3.Multi-dimensional arrays and pointersMulti-dimensional arrays and pointers
4.Two dimensional int array
5.A simple student grades database
6.A very simple text editor
7.A simple Tic Tac Toe gameA simple Tic Tac Toe game
8.For loop: two dimensional array
9.Store value into two dimensional char array and output it
10.English to German Translator
11.Two dimensional char array and for loop
12.the use of a two-dimensional array
13.applying sizeof( ) to determine an array's size