fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int T[5] = {12, 43, 2, 60, 7};
  6. int i, key = 60;
  7. int location = -1;
  8.  
  9. printf("输入的5个数字为:\n");
  10.  
  11. for(i = 0; i < 5; i++)
  12. {
  13. printf("%d ", T[i]);
  14. }
  15.  
  16. printf("\n查找关键字:%d\n", key);
  17.  
  18. for(i = 0; i < 5; i++)
  19. {
  20. if(T[i] == key)
  21. {
  22. location = i + 1;
  23. break;
  24. }
  25. }
  26.  
  27. if(location != -1)
  28. printf("关键字的位置是:%d\n", location);
  29. else
  30. printf("查找失败!\n");
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5340KB
stdin
Standard input is empty
stdout
输入的5个数字为:
12 43 2 60 7 
查找关键字:60
关键字的位置是:4