Write a program to search a given number using binary search.

PROGRAM;   #include<stdio.h> main() { int A[20],n,i,j,temp; clrscr(); printf(“Enter the size of array:\n”); scanf(“%d”,&n); printf(“Enter the array elements:\n”); for(i=0;i<n;i++) scanf(“%d”,&A[i]); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(A[j]>A[j+1]) { temp=A[j]; A[j]=A[j+1]; A[j+1]=temp; } } } printf(“The sorted arrays are as follows:\n”); for(i=0;i<n;i++) printf(“%d\t”,A[i]); printf(“enter the key element to search”) scanf(“%d”,&key); min=0; max=n-1; while(min<=max) { mid=(int)((min+max)/2); if(key==A[mid]) { printf(“key … Read moreWrite a program to search a given number using binary search.

Write a c program to search a given number using linear search.

PROGRAM;   #include<stdio.h> main() { int nums[40]; int key,i,n,location=0; clrscr(); printf(“Enter the size of an array:\n”); scanf(“%d”,&n); printf(“Enter the array element:\n”); for(i=0;i<n;i++) scanf(“%d”,&nums[i]); printf(“Enter the key element:”); scanf(“%d”,&key); for(i=0;i<n;i++) if(nums[i]==key) { location=i+1; break; } if(location==0) { printf(“The given key element doesn’t exist and is not found”); } else printf(“The given key element %d exists and … Read moreWrite a c program to search a given number using linear search.

Write a C program to sort an array using selection sort

PROGRAM:   #include<stdio.h> main() { int i,j,a[10],n,small,index,temp; clrscr(); printf(“\nEnter the number of array\n”); scanf(“%d”,&n); printf(“\nEnter the array elemnts\n”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); for(i=0;i<n;i++) { small=a[i]; index=i; for(j=i+1;j<n;j++) { if(a[j]<small) { small=a[j]; index=j; } } temp=a[index]; a[index]=a[i]; a[i]=temp; } printf(“sorted list is\n”); for(i=0;i<n;i++) printf(“%d\t”,a[i]); getch(); }   OUTPUT: Enter the size of array 5 Enter the array elemnts … Read moreWrite a C program to sort an array using selection sort

Write a c program to sort an array using bubble sort.

PROGRAM;   #include&lt;stdio.h&gt; main() { int A[20],n,i,j,temp; clrscr(); printf(&quot;Enter the size of array:\n&quot;); scanf(&quot;%d&quot;,&amp;n); printf(&quot;Enter the array elements:\n&quot;); for(i=0;i&lt;n;i++) scanf(&quot;%d&quot;,&amp;A[i]); for(i=0;i&lt;n;i++) { for(j=0;j&lt;n;j++) { if(A[j]&gt;A[j+1]) { temp=A[j]; A[j]=A[j+1]; A[j+1]=temp; } } } printf(&quot;The sorted arrays are as follows:\n&quot;); for(i=0;i&lt;n;i++) printf(&quot;%d\t&quot;,A[i]); getch(); }   OUTPUT:   Enter the size of array: 6 Enter the array elements: … Read moreWrite a c program to sort an array using bubble sort.

Write a c program to implement binary tree traversal operations.

program; #include&lt;stdio.h&gt; #include&lt;conio.h&gt; struct node { struct node *left; int data; struct node *right; }; void main() { int num,choice,x; struct node *tree,*ntree; void create(struct node*,int); void inorder(struct node*); void preorder(struct node*); void postorder(struct node*); clrscr(); printf(&quot;Create a Binary tree\n\n&quot;); tree=(struct node*) malloc(sizeof(struct node)); printf(&quot;Input number \n\n&quot;); printf(&quot;Press ctrl+z to EOF\n&quot;); scanf(&quot;%d&quot;,&amp;num); tree-&gt;data=num; tree-&gt;left=NULL; tree-&gt;right=NULL; … Read moreWrite a c program to implement binary tree traversal operations.

Write a c program to implement queue using linked list.

PROGRAM:   #include&lt;stdio.h&gt; struct queue { int data; struct queue *next; }; struct queue *front=NULL; struct queue *rare=NULL; struct queue* getnode(); void Qinsert(); void Qdelete(); void Qdisplay(); void main() { int choice; do { choice=menu(); switch(choice) { case 1: Qinsert(); break; case 2: Qdelete(); break; case 3: Qdisplay(); break; case 4: exit(0); } getch(); } … Read moreWrite a c program to implement queue using linked list.

Write a c program to implement queue using arrays.

PROGRAM ;   #include&lt;conio.h&gt; #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #define SIZE 5 struct queue { int items[SIZE]; int front,rear; }; struct queue q; void qinsert(); void qdelete(); void qdisplay(); void main() { int ch; q.front=q.rear=-1; do { ch=menu(); switch(ch) { case 1: qinsert(); break; case 2: qdelete(); break; case 3: qdisplay(); break; case 4: exit(0); } getch(); }while(1); … Read moreWrite a c program to implement queue using arrays.

Write a c program to evaluate a postfix expression using stack operations.

PROGRAM ;   #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;math.h&gt; #define maxcols 80 #define TRUE 1 #define FALSE 0 struct stack { int top; double items[maxcols]; }; int empty(struct stack*); double eval(char[]); int isdidgit(char); double oper(int, double, double); void push(struct stack*, double); double pop(struct stack*); void main() { char expr[maxcols]; int pos=0; clrscr(); printf(&quot;Input the postfix expression\n&quot;); while((expr[pos++]=getchar())!=&#39;\n&#39;); expr[–pos]=&#39;\0&#39;; … Read moreWrite a c program to evaluate a postfix expression using stack operations.

Write a C program to find the GCD of two numbers using recursion

PROGRAMĀ  #include&lt;stdio.h&gt; main() { int a,b; clrscr(); printf(&quot;Enter the two numbers\n&quot;); scanf(&quot;%d%d&quot;,&amp;a,&amp;b); printf(&quot;THE GCD OF %d AND %d IS %d\n&quot;,a,b,gcd(a,b)); getch(); } int gcd(int a,int b) { if(b!=0) { return (gcd(b,b%a)); } else return(a); }   OUTPUT; Enter the two numbers 30 45 THE GCD OF 30 AND 45 IS 15 Enter the two numbers … Read moreWrite a C program to find the GCD of two numbers using recursion

Write a c program to illustrate stack operations using arrays.

PROGRAM: #include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;stdlib.h&gt; #define STKSIZE 5 struct stack { int elements[STKSIZE]; int top; }; struct stack s; int menu() { int ch; clrscr(); printf(&quot;\n…Stack operations using ARRAY…&quot;); printf(&quot;\n————-**********———–&quot;); printf(&quot;\n 1. Push&quot;); printf(&quot;\n 2. Pop&quot;); printf(&quot;\n 3. Display&quot;); printf(&quot;\n 4. Quit&quot;); printf(&quot;\n Enter your choice:&quot;); scanf(&quot;%d&quot;,&amp;ch); return(ch); } void display() { int i; if(s.top==-1) { … Read moreWrite a c program to illustrate stack operations using arrays.