-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex0611.c
67 lines (44 loc) · 843 Bytes
/
ex0611.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#define NUMBER 10
#define FAILED -1
int search_idx(const int v[], int idx[], int key, int n)
{
int i=0;/* index for loop */;
int j;
for(j=0; j<n; j++){
while(i<n){
if (v[i] == key){
break;
}
i++;
}
if (j==0 && i==n){
break;
}
if (i==n)
break;
idx[j] = i;
i++;
}
return (j==0) ? FAILED : j;
}
int main(void)
{
int i, key, idx,k;
int id[NUMBER],vx[NUMBER];
for(i=0; i<NUMBER; i++){
printf("vx[%d]の値は?",i);
scanf("%d", &vx[i]);
}
printf("探す値は?");
scanf("%d", &key);
if ((idx = search_idx(vx, id, key, NUMBER)) == FAILED)
puts("その数は配列内に存在しません。");
else{
printf("%dは配列内に%d個あります。", key, idx);
for(k=0; k<idx; k++){
printf("id[%d]=%d \n", k, id[k]);
}
}
return 0;
}