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