PROGRAM 4a
PROGRAM 4a
Code
#include <stdio.h>
int left = 0;
if (arr[mid] == target) {
return mid;
left = mid + 1;
else {
right = mid - 1;
} }
return -1;
int main() {
int target;
scanf("%d", &target);
if (result != -1) {
} else {
return 0; }
PROGRAM 2b
Program Name-Binary Search Name-Rishav Kumar Gupta
OUTPUT-
Output –
Code
#include <stdio.h>
if (arr[i] == target) {
return i;
return -1;
int main() {
int target;
scanf("%d", &target);
if (result != -1) {
} else {
return 0;
}
PROGRAM 4a
Program Name-Array implementation of Stack Name-Rishav Kumar
Gupta
Code:
#include<stdio.h>
#define MAXSIZE 5
int s[MAXSIZE],top=-1,item;
int isempty(){
if(top==-1)
return 1;
else
return 0;
int isfull(){
if(top==MAXSIZE-1)
return 1;
else
return 0;
void push(){
printf("Enter element");
scanf("%d",&item);
if(!isfull())
top=top+1;
s[top]=item;
else
printf("stack overflow");
void pop(){
if(!isempty()){
printf("Element deleated:%d",s[top]);
top=top-1;
PROGRAM 4a
Program Name-Array implementation of Stack Name-Rishav Kumar
Gupta
Code:
else{
printf("Stack is empty");
} }
void display(){
for(int i=top;i>=0;i--){
printf("\n%d",s[i]);
} }
int main()
int ch;
while(1){
printf("\n1.push");
printf("\n2.pop");
printf("\n3.display");
printf("\n4.exit");
scanf("%d",&ch);
switch(ch){
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:return 0;
} }
return 0;
}
PROGRAM 4a
Program Name-Array implementation of Stack Name-Rishav Kumar Gupta
OUTPUT:-
1.push
2.pop
3.display
Enter element12
1.push
2.pop
3.display
Enter element23
1.push
2.pop
3.display
Enter element44
1.push
2.pop
3.display
44
23
12
1.push
2.pop
3.display
PS C:\Users\RISHABH\c programs>