C examples for Array:Array Value
Search associated array, a linked array
#include <stdio.h> int main()//from w ww. j a v a2 s .com { int idSearch; // Customer to look for (the key) int found = 0; // Will be 1 (true) if customer is found int id[10] = { 1, 2, 3, 4, 5,6,7, 8, 9, 10 }; float value[10] = { 0.01, 5.3, 1.23, 1.56, 9.08,1.41, 3.00, 2.67, 1.31, 9.54 }; printf("customer number:? "); scanf(" %d", &idSearch); int i = 0; for (i = 0; i<10; i++) { if (idSearch == id[i]) { found = 1; break; } } if (found) { if (value[i] > 3.00) { printf("\nbalance is $%.2f.\n", value[i]); printf(" No additional credit.\n"); } else { printf("\ncredit is good!\n"); } } else { printf("** wrong customer ID."); printf("\n ID %3d was not found in list.\n", idSearch); } return(0); }