06 March 2026

Binary Search

 #include<stdio.h>

#include<conio.h>


void main()

{

int array[99], i, first, last, middle, n, search;

clrscr();


printf("Enter number of elements\n");

scanf("%d",&n);


printf("Enter Elements into the Array\n");

for (i=0; i<n; i++)

{

scanf("%d",&array[i]);

}


printf("Enter value to find\n");

scanf("%d",&search);


first = 0;

last = n - 1;

middle = (first+last) / 2;


while(first <= last)

{

if (array[middle] < search)

{

first = middle + 1;

}

else if(array[middle] == search)

{

printf("%d found at location %d\n", search, middle+1);

break;

}

else

{

last = middle - 1;

}

middle = (first + last)/2;

}

if(first > last)

{

printf("%d is not found in the list.\n", search);

}

getch();

}


Linear Search/ Sequential Search

 #include<stdio.h>

#include<conio.h>


void main()

{

int array[99], num, i, search, found=0;

clrscr();


printf("Enter the number of elements: ");

scanf("%d", &num);


printf("Enter the elements one by one:\\n");

for (i = 0; i < num; i++)

{

scanf("%d", &array[i]);

}


printf("Enter the element to be searched: ");

scanf("%d", &search);


for (i = 0; i < num; i++)

{

if (search == array[i])

{

found = 1;

break;

}

}


if (found == 1)

{

printf("Element is present in the array at position %d\\n", i+1);

}

else

{

printf("Element is not present in the array\\n");

}


getch();

}


03 March 2026

Insertion Sort

 #include<stdio.h>

#include<conio.h>


void main()

{

int arr[99], no, i, j, temp;

clrscr();


printf("Enter number of elements: ");

scanf("%d", &no);


printf("Enter %d integers: ", no);

for (i = 0; i < no; i++)

{

scanf("%d", &arr[i]);

}


for (i = 1; i < no; i++)

{

temp = arr[i];

j = i - 1;


while (j >= 0 && arr[j] > temp)

{

arr[j + 1] = arr[j]; // Move element to the right

j = j - 1;           // Move to the previous element

}

// Move origional element into its correct position

arr[j + 1] = temp;

}


printf("Sorted elements:\n");

for (i = 0; i < no; i++)

{

printf("%d ", arr[i]);

}

printf("\n");


getch();

}


Selection Sort

#include<stdio.h>

#include<conio.h>


void main()

{

int a[99], no, i, j, min, temp;

clrscr();


printf("\nEnter size of an array: ");

scanf("%d", &no);


printf("\nEnter elements of an array:\n");

for(i=0; i<no; i++)

{

scanf("%d", &a[i]);

}


for (i=0; i<no; i++)

{

min = i;

for (j=i+1; j<no; j++)

{

if (a[j] < a[min])

min = j;

}

temp = a[i];

a[i] = a[min];

a[min] = temp;

}


printf("\n\nAfter sorting:\n");

for(i=0; i<no; i++)

{

printf("\n%d", a[i]);

}


getch();

}


Bubble Sort

 #include<stdio.h>

#include<conio.h>


void main()

{

int a[99],i,j,temp,no;

printf("\n Enter the max no.of Elements to Sort: \n");

scanf("%d",&no);

printf("\n Enter the Elements : \n");

for(i=0; i<no; i++)

{

scanf("%d",&a[i]);

}

for(i=0; i<no; i++)

{

for(j=i+1; j<no; j++)

{

if(a[i]>a[j])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

for(i=0; i<no; i++)

{

printf("%d\t",a[i]);

}


getch();

}

20 February 2026

Double Ended Queue without Function

 #include<stdio.h>

#include<conio.h>


void main()

{

int deque[5], ch, i, value, front=-1, rear=-1;

clrscr();

do

{

printf("\nPress 1. insert at the beginning.");

printf("\nPress 2. insert at the end.");

printf("\nPress 3. delete from the beginning.");

printf("\nPress 4. delete from the end.");

printf("\nPress 5. display data.");

printf("\nPress 6. exit from the output screen.");

printf("\nEnter your choice:\n");

scanf("%d",&ch);


switch(ch)

{

case 1:


if(front==0 && rear==4)

{

printf("\nDeque is full.");

}

else

{

printf("\nEnter the data to be added at the beginning:\n");

scanf("%d",&value);

if(front==-1)

{

front=rear=0;

deque[front]=value;

}

/*If deque is full from the front only*/

else if(front==0 && rear!=4)

{

/*Shift the elements from 1 position to its right.*/

for(i=rear;i>=front;i--)

{

deque[i+1]=deque[i];

}

rear++;

deque[front]=value;

}

/*If deque is empty from the front.*/

else if(front>0)

{

front--;

deque[front]=value;

}

printf("\nNumber inserted at the beginning is %d",deque[front]);

}

break;


case 2:


if(front==0 && rear==4)

{

printf("\nDeque is full.");

}

else

{

printf("\nEnter the data to be added at the end:\n");

scanf("%d",&value);

if(rear==-1)

{

front=rear=0;

deque[rear]=value;

}

/*If deque is full from the end only*/

else if(front!=0 && rear==4)

{

/*Shift the elements from 1 position to its left.*/

for(i=front;i<=rear;i++)

{

deque[i-1]=deque[i];

}

front--;

deque[rear]=value;

}

/*If deque is empty from the end.*/

else if(rear<4)

{

rear++;

deque[rear]=value;

}

printf("\nNumber inserted at the end is %d",deque[rear]);

}

break;


case 3:

if(front==-1)

{

printf("Deque is empty.");

}

else

{

if(front==rear)

{

value=deque[front];

front=rear=-1;

}

else

{

value=deque[front];

front++;

}

}

printf("\nNumber deleted from the beginning is %d",value);


break;


case 4:

if(rear==-1)

{

printf("Deque is empty.");

}

else

{

if(front==rear)

{

value=deque[rear];

front=rear=-1;

}

else

{

value=deque[rear];

rear--;

}

}

printf("\nNumber deleted from the end is %d",value);


break;


case 5:


if(front==-1 || rear==-1)

{

printf("Deque is empty.");

}

else

{

for(i=front;i<=rear;i++)

{

printf("%5d",deque[i]);

}

}

break;


case 6:

exit(0);


default:

printf("\nYou have entered wrong choice!.");

}

}while(ch!=6);


getch();

}


11 November 2022

Array

 

Array:

 

#include<stdio.h>

#include<conio.h>

 

void main()

{

                int i, no[10];

                clrscr();

                printf(“Enter values in an array”);

                printf(“--------------------------------“);

 

                // Input/ Scan the numbers

                for(i=0; i<10; i++)

                {

                printf(“Enter value %d”, i+1);

                scanf(“%d”, &no[i]);

}

 

// Output/ Print the numbers

for(i=0; i<10; i++)

                {

                printf(“Value %d is %d”, i+1, no[i]);         

}

                getch();

}

 

 

Exercise:

1. Define an array of 5 employee. Enter the id number of 5 employee and print it.

2. Define an array of 5 students. Enter the percentage of 5 studnets and print it.