Program Using Function of Array
Program Using Function of Array
Program Using Function of Array
Program:
#include <stdio.h>
int main() {
result = calculateSum(num);
return 0;
sum += num[i];
return sum;
}
OUTPUT:
Result=162.50
C PROGRAMMING USING POINTERS AND STRUCTURES
PROGRAM:
#include <stdio.h>
void geeks()
int* ptr;
ptr = &var;
int main()
geeks();
return 0;
}
OUTPUT
Value at var = 20
Value at *ptr = 20
STRUCTURES
POINTER:
#include <stdio.h>
struct Point {
int x, y, z;
};
int main()
struct Point p1 = { .y = 0, .z = 1, .x = 2 };
struct Point p2 = { .x = 20 };
return 0;
}
OUTPUT:
x = 2, y = 0, z = 1
x = 20
IMPLEMENTATION OF BINARY TREE
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
};
if(t != NULL)
inorder(t->prev);
printf("%d->",t->data);
inorder(t->next);
if(t == NULL)
{
t = (list*)malloc(sizeof(list));
t->data = key;
t->prev = NULL;
t->next = NULL;
t->prev = insert(key,t->prev);
t->next = insert(key,t->next);
return(t);
int main()
current = (list*)malloc(sizeof(list));
printf("Enter data:");
scanf("%d",¤t->data);
current->next = NULL;
current->prev = NULL;
head = current;
while(z == 1)
printf("Enter data:");
scanf("%d",&y);
current = insert(y,current);
printf("want to insert more:");
scanf("%d",&z);
printf("\nInorder Traversal:");
newn = head;
inorder(newn);
}
OUTPUT:
Enter data:300
Enter data:90
Inorder traversal:90->300->
ARRAY IMPLEMENTATION OF STACK AND QUEUE
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 4
void push();
void pop();
void show();
int main()
int choice;
while (1)
scanf("%d", &choice);
switch (choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
show();
break;
case 4:
exit(0);
default:
printf("\nInvalid choice!!");
void push()
int x;
if (top == SIZE - 1)
printf("\nOverflow!!");
else
top = top + 1;
inp_array[top] = x;
void pop()
if (top == -1)
printf("\nUnderflow!!");
else
top = top - 1;
void show()
if (top == -1)
printf("\nUnderflow!!");
else
}
OUTPUT:
3.Show
4.End
3.Show
4.End
3.Show
4.End
3
QUEUE
PROGRAM:
#include <stdio.h>
#define MAX 50
void insert();
void delete();
void display();
int queue_array[MAX];
int rear = - 1;
int front = - 1;
main()
int choice;
while (1)
printf("4.Quit \n");
scanf("%d", &choice);
switch (choice)
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
} /* End of switch */
} /* End of while */
} /* End of main() */
void insert()
int add_item;
if (rear == MAX - 1)
else
if (front == - 1)
front = 0;
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
} /* End of insert() */
void delete()
return ;
else
front = front + 1;
} /* End of delete() */
void display()
int i;
if (front == - 1)
else
printf("Queue is : \n");
printf("\n");
} /* End of display() */
OUTPUT:
4.Quit
4.Quit
4.Quit
4.Quit
4.Quit
4.Quit
Queue is :
15 20 30
4.Quit
PROGRAM:
#include<stdio.h>
scanf ("%d",&n);
");
");
if (a[i] == key){
flag = 1;
break;
if (flag == 1)
printf("search is successful:");
Else:
printf("search is unsuccessfull:");
return 0;
}
OUTPUT:
45
13
67
78
search is successful:
IMPLEMENTATION OF HASHING ANY TWO COLLISION TECHNIQUES
PROGRAM:
#include <stdio.h>
#include<stdlib.h>
#define TABLE_SIZE 10
int h[TABLE_SIZE]={NULL};
void insert()
int key,index,i,flag=0,hkey;
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE;i++)
index=(hkey+i)%TABLE_SIZE;
if(h[index] == NULL)
h[index]=key;
break;
}
if(i == TABLE_SIZE)
void search()
int key,index,i,flag=0,hkey;
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE; i++)
index=(hkey+i)%TABLE_SIZE;
if(h[index]==key)
break;
if(i == TABLE_SIZE)
void display()
int i;
printf("\nelements in the hash table are \n");
main()
int opt,i;
while(1)
scanf("%d",&opt);
switch(opt)
case 1:
insert();
break;
case 2:
display();
break;
case 3:
search();
break;
case 4:exit(0);
}
OUTPUT:
Output
12
13
22
at index 0 value = 0
at index 1 value = 0
at index 2 value = 12
at index 3 value = 13
at index 4 value = 22
at index 5 value = 0
at index 6 value = 0
at index 7 value = 0
at index 8 value = 0
at index 9 value = 0
12
23
23
4
ARRAY IMPLEMENTATION OF LIST ADT
PROGRAM:
#include<stdio.h>
#include<alloc.h>
#include<conio.h>
struct list
int capacity;
int size;
int *array;
};
int Isempty(LIST L)
return L->size==0;
void MakeEmpty(LIST L)
if(Isempty(L))
else
L->size=0;
printf("\n Now List becomes Empty");
LIST L;
if(L==NULL)
else
L->capacity=max;
L->array=(int*)malloc(sizeof(int)*max);
if(L->array==NULL)
else
L->size=0;
return L;
int Isfull(LIST L)
return L->size==L->capacity;
}
void Insert(int x,LIST L,POSITION P)
int i;
if(Isfull(L))
else
for(i=L->size-1;i>=P;i--)
L->array[i+1]=L->array[i];
L->size++;
L->array[P]=x;
POSITION P;
P=-1;
while(P!=L->size&&L->array[P+1]!=x)
P++;
return P;
POSITION P;
P=0;
while(P!=L->size&&L->array[P]!=x)
P++;
return P;
int i;
POSITION P;
P=Find(x,L);
if(P==L->size)
else
for(i=P;i<L->size;i++)
L->array[i]=L->array[i+1];
L->size--;
LIST Deletelist(LIST L)
MakeEmpty(L);
free(L);
L=NULL;
return L;
void Display(LIST L)
int i;
for(i=0;i<L->size;i++)
printf("\n %d",L->array[i]);
“Larray.c” File:
#include"Larray.h"
#include<stdlib.h>
void main()
LIST L=NULL;
POSITION P;
int a,choice,ch,element;
clrscr();
printf("\n\n1.Create\n2.Insert\n3.Delete\n4.Display\n5.MakeEmpty\n6.Find\n7.IsEmpty\n8.IsFull\
n9.Deletelist\n10.Exit\n");
A:
scanf("%d",&choice);
switch(choice)
case 1:
if(L==NULL)
L=Createlist(5);
else
break;
case 2:
if(L==NULL)
else
scanf("%d",&element);
if(L->size==0)
Insert(element,L,0);
else
scanf("%d",&ch);
if(ch==1)
Insert(element,L,0);
else
if(ch==2)
Insert(element,L,L->size);
else
if(ch==3)
scanf("%d",&a);
P=Find(a,L);
if(P<L->size)
Insert(element,L,P);
else
else
break;
case 3:
if(L==NULL)
if(Isempty(L))
printf("\nList is empty");
else
scanf("%d",&a);
Delete(a,L);
break;
case 4:
if(L==NULL)
else
if(Isempty(L))
printf("\nList is empty");
else
{
Display(L);
break;
case 5:
if(L==NULL)
else
MakeEmpty(L);
break;
case 6:
if(L==NULL)
else
if(Isempty(L))
else
scanf("%d",&a);
P=Find(a,L);
break;
case 7:
if(L==NULL)
if(Isempty(L))
else
break;
case 8:
if(L==NULL)
else
if(Isfull(L))
else
break;
case 9:
if(L==NULL)
else
L=Deletelist(L);
break;
case 10:
exit (0);
break;
default:
}
OUTPUT:
OUTPUT:
1.Create
2.Insert
3.Delete
4.Display
5.MakeEmpty
6.Find
7.IsEmpty
8.IsFull
9.Deletelist
10.Exit
Enter Ur Option: 1
PROGRAM:
#include <stdio.h>
#define max 10
int a[11] = { 10, 14, 19, 26, 27, 31, 33, 35, 42, 44, 0 };
int b[10];
for(l1 = low, l2 = mid + 1, i = low; l1 <= mid && l2 <= high; i++) {
b[i] = a[l1++];
else
b[i] = a[l2++];
b[i++] = a[l1++];
b[i++] = a[l2++];
a[i] = b[i];
}
void sort(int low, int high) {
int mid;
sort(low, mid);
sort(mid+1, high);
} else {
return;
int main() {
int i;
sort(0, max);
}
OUTPUT:
Output
10 14 19 26 27 31 33 35 42 44 0
0 10 14 19 26 27 31 33 35 42 44
IMPLEMENTATION OF BINARY SEARCH TREE
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct node {
int key;
};
// Create a node
temp->key = item;
return temp;
// Inorder Traversal
if (root != NULL) {
// Traverse left
inorder(root->left);
// Traverse root
inorder(root->right);
// Insert a node
else
return node;
current = current->left;
return current;
}
// Deleting a node
else {
if (root->left == NULL) {
free(root);
return temp;
free(root);
return temp;
root->key = temp->key;
// Delete the inorder successor
return root;
// Driver code
int main() {
inorder(root);
inorder(root);
}
OUTPUT:
INORDER TRAVERSAL:1->3->4->6->7->8->10->14->
AFTER DELETING 10
INORDER TRAVERSAL:1->3->4->6->7->8->14->
DEVELEPMENT OF REAL TIME APPLICATIONS
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
void draw()
if (i == 0 || i == width - 1 || j == 0
|| j == height - 1) {
printf("#");
else {
printf(" ");
printf("\n");
int main()
draw();
return 0;
}
OUTPUT:
#############
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#############
APPLICATION OF STACK,QUEUE AND LIST
PROGRAM:
STACK:
#include <stdio.h>
int MAXSIZE = 8;
int stack[8];
int isempty() {
if(top == -1)
return 1;
else
return 0;
int isfull() {
if(top == MAXSIZE)
return 1;
else
return 0;
int peek() {
return stack[top];
}
int pop() {
int data;
if(!isempty()) {
data = stack[top];
top = top - 1;
return data;
} else {
if(!isfull()) {
top = top + 1;
stack[top] = data;
} else {
int main() {
push(3);
push(5);
push(9);
push(1);
push(12);
push(15);
printf("Elements: \n");
while(!isempty()) {
printf("%d\n",data);
return 0;
}
OUTPUT:
Output
Elements:
15
12