fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int codeList[] = {10,15,20,25,30};
  6. size_t itemsCount = (sizeof(codeList)) / sizeof(codeList[0]);
  7.  
  8. int item = 10;
  9.  
  10. size_t index = 0;
  11. for (; index < itemsCount; index++)
  12. {
  13. if (item == codeList[index])
  14. {
  15. break;
  16. }
  17. }
  18.  
  19. if (index < itemsCount)
  20. {
  21. printf("Item %d found at index %d\n", item, index);
  22. }
  23. else
  24. {
  25. printf("Item %d not found\n", item);
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5452KB
stdin
Standard input is empty
stdout
Item 10 found at index 0