1、
#include <stdio.h> #define NUMBER 7 int search(const int x[], int y[], int key, int n) { int i, times = 0; for(i = 0; i < n; i++) { if(x[i] == key) { y[times] = i; times++; } } return times; } void print(const int x[], int n) { int i; for(i = 0; i < n; i++) { printf("%d ", x[i]); } } int main(void) { int i, ky, a[NUMBER], b[NUMBER], num; puts("please input the elements."); for(i = 0; i < NUMBER; i++) { printf("NO.%d = ", i + 1); scanf("%d", &a[i]); } printf("the destination ky: "); scanf("%d", &ky); printf("the times: %d ", num = search(a, b, ky, NUMBER)); if(num != 0) puts("show the index."); print(b,num); return 0; }