-
Notifications
You must be signed in to change notification settings - Fork 1
/
8.CPP
40 lines (35 loc) · 819 Bytes
/
8.CPP
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
#include<iostream.h>
#include<conio.h>
int search(int arr[], int size, int key){
int i;
for(i=0;i<size;i++){
if(arr[i]==key)
return i;
}
return -1;
}
int search(double arr[], int size, double key){
int i;
for(i=0;i<size;i++){
if(arr[i]==key)
return i;
}
return -1;
}
int main(){
int intArray[] = {10, 20, 30, 40};
double doubleArray[] = {1.1, 2.2, 3.3, 4.4};
clrscr();
int intIndex = search(intArray, 4, 30);
if(intIndex!=-1){
cout<<"Integer key value found at index "<<intIndex<<"."<<endl;
}
else cout<<"Integer key value is not found.";
int doubleIndex = search(doubleArray, 4, 2.2);
if(doubleIndex!=-1){
cout<<"Double key value found at index "<<doubleIndex<<"."<<endl;
}
else cout<<"Double key value is not found.";
getch();
return 0;
}