-
Notifications
You must be signed in to change notification settings - Fork 3
/
Week1 20 Jan Q4.c
52 lines (38 loc) · 995 Bytes
/
Week1 20 Jan Q4.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
#include<stdio.h>
main(){
int a[10], N, i, k;
for(i=0;i<=9;i++){
checker(a,i);
}
printf("\nInput No. to search..");
scanf("%d",&N);
int result = binary_search(a,N);
if(result!=0){
printf("\nKey %d is Found at %d", N, result);
}else{
printf("\nKey not Found");
}
}
int checker(int a[], int i){
int j,u=0,k;
printf("Input No. %d..\n",(i+1));
scanf("%d",&k);
for(j=0;j<i;j++){
if(a[j]>k){ u++; }
}
if(u>0){
printf("\nInvalid Input.. Non Ascending.. %d numbers greater found.. Retype\n",u);
checker(a,i);
}else{
printf("Input Ok!\n");
a[i]=k;
}
}
int binary_search(int a[], int X){
int i;
for(i=0;i<10;i++){
if(a[i]==X){
return i;
}
}
}