赞
踩
- #include <stdio.h>
- #define NUMBER 7
-
- int search(const int v[], int idx[], int key, int n) {
- int i, a = 0;
- for (i = 0; i < n; i++)
- {
- if (v[i] == key) {
- idx[a] = i;
- a++;
- }
- }
- return a;
- }
- int main(void)
- {
- int i, x, n;
- int a[NUMBER];
- int idx[NUMBER];
- for (i = 0; i < NUMBER; i++) {
- printf("a[%d] = ", i); scanf("%d", &a[i]);
- }
- printf("key = "); scanf("%d", &x);
- n = search(a, idx, x, NUMBER);
- printf("有%d个,分别在:\nidx{ ", n);
- for (i = 0; i < n; i++) {
- printf("%d ", idx[i]);
- }
- printf("}");
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。