#include<stdio.h> int main() { int x, i, a[10] = { 11,5,78,22,53,66,34,89,45 };//數組初始化 printf("請輸入要查找的數據:\n"); scanf_s("%d", &x); for (i = 0; i < 10; i++)//循環查找,存在相等元素提前結束循環,否則i++繼續比較 if (a[i] == x) break; if (i < 10) printf("%d在數組的第%d個單元\n", x, i); printf("Not Found!\n"); return 0; }
