blob: 84d1f51f307252d8b1aad3c433135fef27334381 (
plain)
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
|
int MAX=1000;
int intArray[1000];
int find(int data){
int comparisons;
int index;
int i;
comparisons = 0;
index = -1;
i=0;
while(i<MAX){
// count the comparisons made
comparisons = comparisons + 1;
// if data found, break the loop
if(data == intArray[i]){
index = i;
break;
}
i=i+1;
}
putint(comparisons);
putch(10);
return index;
}
void display(){
int i;
i=0;
while(i<MAX){
putint(intArray[i]);
i=i+1;
}
putch(10);
}
int main(){
int i;
int location;
int QQQQ;
QQQQ=getint();
i=0;
while (i<MAX) {
intArray[i] = i;
i=i+1;
}
display();
location = find(QQQQ);
putint(location);
putch(10);
return 0;
}
|