You are on page 1of 1

GDB online Debugger | Compiler - Code, Compile, Run, Debug online ... https://www.onlinegdb.

com/

You need to verify email to use all features of IDE. Follow instructio
 OnlineGDB
beta (/)    Run  Debug  Stop  Share  Save { } Beautify 
online compiler and 1 //program to implement binary search//
main.c
debugger for c/c++ 2 #include <stdio.h>
3 #include<stdlib.h>
Welcome, Mohd Ali 4 int main()
(/profile/)  5 {
(/notifications) 6 int a[20],n,i,key,low,high,mid;
7 printf("input array size : ");
7 8 scanf("%d",&n);
9 printf("\nenter array elements : ");
Create New Project (/) 10 for(i=0;i<n;i++)
My Projects (/myfiles) 11 scanf("%d",&a[i]);
12 printf("\ninput key element : ");
Classroom new 13 scanf("%d",&key);
(/classroom) 14 low=0;
Learn Programming 15 high=n-1;
16
(https://learn.onlinegdb.com while(low<=high)
17 {
Programming 18 mid=(low+high)/2;
Questions 19 if(a[mid]==key)
(https://question.onlinegdb.com
20 {
Logout (/logout) 21 printf("\n key element %d is found at %d position-succ
22 exit(1);
23 }
24 else if(a[mid]>key)
25 high=mid-1;
167K  26 else
27 low=mid+1;
28 }

   input
About (/about) • FAQ
(/faq) • Blog (/blog/) •
Terms of Use
(/termsofuse) • Contact
Us (/contact) • GDB
Tutorial
(http://www.gdbtutorial.com/
• Credits (/credits) •
Privacy (/privacy)
© 2016 - 2022 GDB
Online

1 of 1 8/16/2022, 2:34 AM

You might also like