EC CODING New - Merged
EC CODING New - Merged
PREPARED BY
Mr. S. Alaguganesan, AP/AI&DS
LIST OF EXPERIMENTS
1. Practice of C programming using statements, expressions, decision making and
iterative statements
2. Practice of C programming using Functions and Arrays
3. Implement C programs using Pointers and Structures
4. Implement C programs using Files
5. Development of real time C applications
6. Array implementation of List ADT
7. Array implementation of Stack and Queue ADTs
8. Linked list implementation of List, Stack and Queue ADTs
9. Applications of List, Stack and Queue ADTs
10. Implementation of Binary Trees and operations of Binary Trees
11. Implementation of Binary Search Trees
12. Implementation of searching techniques
13. Implementation of Sorting algorithms: Insertion Sort, Quick Sort, Merge Sort
14. Implementation of Hashing – any two collision techniques
Table of Contents
Program
#include <stdio.h>
#include<stdlib.h>
#include <conio.h>
main()
{
int n1, n2,result; char op;
clrscr();
printf("\n SimpleCalculator");
printf("\n + Summation");
printf("\n - Difference");
printf("\n * Product");
printf("\n / Quotient");
printf("\n % Remainder");
printf("\n Enter the operator : ");
op = getchar();
printf("Enter operand1 and operand2 : ");
scanf("%d%d",&n1,&n2);
switch(op)
{
case '+':
result = n1 +n2; break;
case '-':
result = n1 -n2; break;
case '*':
result = n1 *n2; break;
case '/':
result = n1 /n2; break;
case '%':
result = n1 %n2; break;
default:
printf("Invalidoperator");
exit(-1);
}
printf("%d %c %d = %d", n1, op, n2, result);
getch();
}
Output
Simple Calculator
+ Summation
- Difference
* Product
/ Quotient
% Remainder
Enter the operator : -
Enter operand1 and operand2 : 2 4 2 - 4 = -2
Simple Calculator
+ Summation
- Difference
* Product
/ Quotient
% Remainder
Enter the operator : %
Enter operand1 and operand2 : 5 2 5 % 2 = 1
Ex. No. 1b Armstrong Numbers
Program
#include <stdio.h>
#include<conio.h>
main()
{
int i, n, d, sum;
clrscr();
Output
Program
#include <stdio.h>
#include<conio.h>
main()
{
int n, d, sum;
clrscr();
printf("Enter a number :");
scanf("%d", &n);
sum = 0;
while(n)
{
d = n % 10;
sum = sum + d;
n = n / 10;
}
Output
Program
#include <stdio.h>
#include<conio.h>
main()
{
int i=0, j, n;
clrscr();
printf("\n Enter value for n : ");
scanf("%d", &n);
printf("First N numbers divisible by 3:");
for(j=1; ;j++)
{
if (j%3 == 0)
{
i++;
printf("%d", j);
}
if (i == n)
break;
}
getch();
}
Output
Program
#include <stdio.h>
#include <conio.h>
longfactorial(int);
main()
{
int n; long f;
clrscr();
printf("Enter a number :");
scanf("%d", &n);
f = factorial(n);
printf("Factorial value : %ld", f);
getch();
}
long factorial(int n)
{
int i;
long f = 1;
for(i=n; i>=1;i--)
f = f * i;
return f;
}
Output
Enter a number : 6
Factorial value :720
Enter a number : 12
Factorial value :479001600
Ex. No. 1f Array Maximum
Program
/* Maximum of an array */
#include<stdio.h>
#include<conio.h>
main()
{
int a[10];
int i, max, n;
clrscr();
printf("Enter number of elements : ");
scanf("%d", &n);
printf("Enter Array Elements \n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
max = a[0];
for(i=1; i<n;i++)
{
if (max < a[i])
max = a[i];
}
Output
Program
#include <stdio.h>
#include<conio.h>
main()
{
int a[5][5], b[5][5], c[5][5];
int i, j, row,col;
clrscr();
printf("\nEnter order for matrix : ");
scanf("%d%d", &row, &col);
printf("\nEnter elements for A matrix\n");
for(i=0; i<row; i++)
for(j=0; j<col; j++)
scanf("%d",&a[i][j]);
printf("\nEnter elements for B matrix\n");
for(i=0; i<row; i++)
for(j=0; j<col; j++)
scanf("%d",&b[i][j]);
for(i=0; i<row; i++)
for(j=0; j<col;j++)
c[i][j] = a[i][j] + b[i][j];
printf("\n Contents of C matrix \n");
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
printf("%3d", c[i][j]);
}
printf("\n");
}
getch();
}
Output
Contents of Cmatrix
3 3
4 5
Ex. No. 2a Palindrome
Program
#include <string.h>
#include<stdio.h>
#include<conio.h>
main()
{
charstr[40],rev[40];
int x;
clrscr();
printf("Enter the string:");
scanf("%s", str);
strcpy(rev, str);
strrev(rev);
printf("Reversed string is: %s \n",rev);
x = strcmpi(str,rev);
if (x == 0)
printf("Given string is a palindrome");
else
printf("Given string is not a palindrome");
getch();
}
Output
Program
/* Alphabetical Order */
#include <stdio.h>
#include <conio.h>
#include<string.h>
main()
{
char name[20][15],t[15];
int i, j, n;
clrscr();
printf("Enter number of students : ");
scanf("%d", &n);
printf("\nEnter studentnames\n");
for(i=0; i<n; i++)
scanf("%s", name[i]);
printf("\nAlphabetical Order\n");
for(i=0; i<n; i++)
printf("%s\n",name[i]);
getch();
}
Output
Enter studentnames
Raghu
Praba Gopal
Anand
Venkat
Kumar
Saravana
Naresh
Christo
Vasanth
Alphabetical Order
Anand
Christo
Gopal Kumar
Naresh Praba
Raghu
Saravana
Vasanth
Venkat
Ex. No. 3a Pass By Value / Reference
Program
/* Pass by Reference*/
void swapref(int *x, int *y)
{
int t;
t = *x;
*x = *y;
*y = t;
}
Output
Program
/* Payroll Generation */
#include<stdio.h>
#include<conio.h>
struct employee
{
int empid;
charname[15];
int basic;
float hra;
float da;
float it;
float gross;
float netpay;
};
main()
{
struct employeeemp[50];
inti, j, n;
clrscr();
printf("\n Enter No. of Employees : ");
scanf("%d", &n);
for(i=0; i<n ;i++)
{
printf("\n Enter Employee Details\n");
printf("Enter Employee Id : ");
scanf("%d", &emp[i].empid);
printf("Enter Employee Name : ");
scanf("%s", emp[i].ename);
printf("Enter Basic Salary: ");
scanf("%d", &emp[i].basic);
}for(i=0; i<n; i++)
{
emp[i].hra = 0.02 * emp[i].basic;
emp[i].da = 0.01 * emp[i].basic;
emp[i].it = 0.05 * emp[i].basic;
emp[i].gross = emp[i].basic + emp[i].hra + emp[i].da;
emp[i].netpay = emp[i].gross - emp[i].it;
}
printf("\n\n\n\t\t\t\tXYZ&Co.Payroll\n\n");
for(i=0;i<80;i++)
printf("*");
printf("EmpId\tName\t\tBasic\t HRA\t DA\t IT\t Gross\t\tNet Pay\n");
for(i=0;i<80;i++)
printf("*");
for(i=0; i<n; i++)
{
printf("\n%d\t%-15s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f", emp[i].empid,
emp[i].ename,emp[i].basic,emp[i].hra,
emp[i].da, emp[i].it, emp[i].gross,emp[i].netpay);
}
printf("\n"); for(i=0;i<80;i++)
printf("*");
getch();
}
Output
********************************************************************************
Ex. No.3c Cricket Team Stats
Program
/* 3b - Cricket Statistics*/
#include <stdio.h>
#include <conio.h>
#include<string.h>
struct cricket
{
int plcode;
char name[15];
char tname[15];
float btavg;
};
main()
{
struct cricket player[50],temp;
int i, j, n;
clrscr();
printf("\n Enter No. of Players : ");
scanf("%d", &n);
for(i=0; i<n; i++)
{
printf("\nEnter PlayerDetails\n");
printf("Enter player code : ");
scanf("%d", &player[i].plcode);
printf("Enter player name : ");
scanf("%s", player[i].name);
printf("Enter team name : ");
scanf("%s", player[i].tname);
printf("Enter batting average : ");
scanf("%f", &player[i].btavg);
}
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if (strcmp(player[i].tname, player[j].tname) >0)
{
temp = player[i]; player[i] =player[j]; player[j] = temp;
}
}
}
printf("\n\t PLAYER DETAILS-TEAM WISE \n");
printf("\n P.Code \t");
printf("%-15s %-15s", "Name", "Team");
printf("Bat. Avg \n");
for(i=0; i<n; i++)
{
printf("%d\t", player[i].plcode);
printf("%-15s",player[i].name);
printf("%-15s", player[i].tname);
printf("%.2f\n", player[i].btavg);
}
getch();
}
Output
Program
#include <stdio.h>
#include<conio.h>
struct complex
{
int real; int img;
};
main()
{
struct complex c1, c2, c3;
printf("Enter the real part for first complex number: ");
scanf("%d", &c1.real);
printf("Enter imaginary part for first complex number: ");
scanf("%d", &c1.img);
printf("First complex No.: %d + %di\n", c1.real, c1.img);
printf("Enter the real part for second complex number: ");
scanf("%d", &c2.real);
printf("Enter imaginary part for second complex number: ");
scanf("%d", &c2.img);
printf("Second complex No.: %d + %di\n", c2.real, c2.img);
c3.real = c1.real +c2.real;
c3.img = c1.img + c2.img;
printf("Sum of complex Nos.: %d + %di\n", c3.real, c3.img);
getch();
}
Output
Program
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
main()
{
int i, n, sum, min,max;
int *arr, *p;
printf("Enter number of elements : ");
scanf("%d", &n);
arr = (int *) malloc(n * sizeof(int));
if(arr == NULL)
{
printf("Memory allocation notfeasible\n");
exit(-1);
}
printf("Enter array elements: \n");
for(p=arr; p<arr+n; p++)
scanf("%d", p);
sum = 0;
min = max = *arr;
for(p=arr; p<arr+n;p++)
{
if(min > *p)
min = *p;
if(max < *p)
max = *p;
sum = sum + *p;
}
printf("Sum of array : %d \n", sum);
printf("Array minimum is : %d \n", min);
printf("Array maximum is : %d \n", max);
free(arr);
getch();
}
Output
Program
#include <stdio.h>
#include <conio.h>
#include<process.h>
#include <alloc.h>
#include <string.h>
struct node
{
int label;
struct node *next;
};
main()
{
int ch, fou=0;
int k;
struct node *h, *temp, *head, *h1;
case 3:
printf("\n\n HEAD ->");
h=head;
while (h->next != NULL)
{
h = h->next;
printf("%d -> ",h->label);
}
printf("NULL");
break;
case 4:
exit(0);
}}}
Output
Program
{
printf("%4d", stack[i]);
}
printf("\n");
}}
main()
{
int ch=0, val;
clrscr();
while(ch != 4)
{
printf("\n STACK OPERATION \n");
printf("1.PUSH ");
printf("2.POP ");
printf("3.VIEW ");
printf("4.QUIT \n");
printf("Enter Choice :");
scanf("%d", &ch);
switch(ch)
{
case 1:
if(top < max-1)
{
printf("\nEnter Stack element : ");
scanf("%d", &val);
push(val);
}
else
printf("\n Stack Overflow\n");
break;
case 2:
if(top < 0)
printf("\n Stack Underflow\n");
else
{
val = pop();
printf("\n Popped element is %d\n",val);
}
break;
case 3:
view();
break;
case 4:
exit(0); default:
printf("\n Invalid Choice \n");
}}}
Output
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 1
Enter Stack element :12 STACK
OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 1
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 1
Enter Stack element :34 STACK
OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 1
Enter Stack element :45 STACK
OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 3
Top--> 45 34 23 12
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 2 Popped
element is45
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 3
Top--> 34 23 12
STACK OPERATION
1. PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 4
Ex. No. 5b Queue Array
Program
#include <stdio.h>
#include<conio.h>
#define max 5
static intqueue[max];
int front = -1;
int rear= -1;
void insert(int x)
{
queue[++rear] =x;
if (front == -1)
front = 0;
}
int remove()
{
int val;
val = queue[front];
if (front==rear &&rear==max-1)
front = rear = -1;
else
front ++;
return (val);
}
void view()
{
int i;
if (front == -1)
printf("\n Queue Empty\n");
else
{
printf("\n Front-->");
for(i=front; i<=rear;i++)
printf("%4d", queue[i]);
printf(" <--Rear\n");
}}
main()
{
int ch= 0,val;
clrscr();
while(ch != 4)
{
printf("\n QUEUE OPERATION\n");
printf("1.INSERT ");
printf("2.DELETE ");
printf("3.VIEW ");
printf("4.QUIT\n");
printf("Enter Choice :");
scanf("%d", &ch);
switch(ch)
{
case 1:
if(rear < max-1)
{
printf("\n Enter element to be inserted : ");
scanf("%d", &val);
insert(val);
}
else
printf("\n Queue Full\n");
break;
case 2:
if(front == -1)
printf("\n Queue Empty\n");
else
{
val = remove();
printf("\n Element deleted : %d \n",val);
}break;
case 3:
view();
break;
case 4:
exit(0); default:
printf("\n Invalid Choice \n");
}}}
Output
QUEUE OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice :1
Enter element to be inserted : 12 QUEUE
OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice :1
Enter element to be inserted : 23 QUEUE
OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice :1
Enter element to be inserted : 34 QUEUE
OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice :1
Enter element to be inserted : 45 QUEUE
OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice :1
Enter element to be inserted : 56 QUEUE
OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice : 1
Queue Full
QUEUE OPERATION
1. INSERT 2.DELETE 3.VIEW 4.QUIT
Enter Choice : 3
Front--> 12 23 34 45 56 <--Rear
Ex. No. 6a Stack Using Linked List
Program
#include <stdio.h>
#include <conio.h>
#include<process.h>
#include <alloc.h>
struct node
{
int label;
struct node *next;
};
main()
{
int ch = 0; int k;
struct node *h, *temp, *head;
scanf("%d", &ch);
switch(ch)
{
case 1:
/* Create a new node */
temp=(structnode*)(malloc(sizeof(struct node)));
printf("Enter label for new node : ");
scanf("%d", &temp->label);
h = head;
temp->next =h->next;
h->next = temp; break;
case 2:
/* Delink the first node*/
h = head->next;
head->next = h->next;
printf("Node %s deleted\n", h->label); free(h);
break;
case 3:
printf("\n HEAD ->");
h = head;
/* Loop till last node*/
while(h->next != NULL)
{
h = h->next;
printf("%d -> ",h->label);
}
printf("NULL \n"); break;
case 4:
exit(0);
}}}
Output
.
Ex. No. 6b Queue Using Linked List
Program
#include <stdio.h>
#include <conio.h>
#include<process.h>
#include <alloc.h>
struct node
{
int label;
struct node *next;
};
main()
{
int ch=0; int k;
struct node *h, *temp, *head;
while(1)
{
printf("\n Queue using Linked List \n");
printf("1->Insert ");
printf("2->Delete ");
printf("3->View ");
printf("4->Exit \n");
printf("Enter your choice :");
scanf("%d", &ch);
switch(ch)
{
case 1:
/* Create a new node */
temp=(structnode*)(malloc(sizeof(struct node)));
printf("Enter label for new node : ");
scanf("%d", &temp->label);
case 3:
printf("\n\nHEAD ->");
h=head;
while (h->next!=NULL)
{
h = h->next;
printf("%d -> ",h->label);
}
printf("NULL \n");
break;
case 4:
exit(0);
}}}
Output
Program
#include <stdio.h>
#include <conio.h>
#include<string.h>
#define MAX 20
int prcd(charsymbol)
{
switch(symbol)
{
case '+':
case '-':
return 2;
break;
case '*':
case '/':
return 4;
break;
case '^':
case '$':
return 6;
break;
case '(':
case ')':
case '#':
return 1;
break;
}
}
while(stack[top] != '#')
{
postfix[j] = pop();
j++;
}
postfix[j] = '\0';
}
main()
{
charinfix[20],postfix[20]; clrscr();
printf("Enter the valid infix string: ");
gets(infix);
convertip(infix, postfix);
printf("The corresponding postfix string is: ");
puts(postfix);
getch();
}
.
Ex. No. 7b Postfix Expression Evaluation
Date:
Program
#include <stdio.h>
#include<conio.h>
struct stack
{
}s;
case '+':
d1 = s.a[s.top--];
d2 = s.a[s.top--];
s.a[++s.top] = d1 +d2;
break;
case '-':
d2 =s.a[s.top--];
d1 =s.a[s.top--];
s.a[++s.top] = d1 -d2;
break;
case '*':
d2 = s.a[s.top--];
d1 = s.a[s.top--];
s.a[++s.top] =d1*d2;
break;
case '/':
d2 = s.a[s.top--];
d1 = s.a[s.top--];
s.a[++s.top] = d1 /d2; break;
}}
printf("\n Expression value is %5.2f", s.a[s.top]);
getch();
}
Output
Program
main()
{
inti,j,k,n,ttur,twat; float
awat,atur;
p[0].wtime = 0; for(i=0;
i<n;i++)
{
p[i+1].wtime = p[i].wtime + p[i].btime; p[i].ttime =
p[i].wtime +p[i].btime;
}
ttur = twat = 0; for(i=0;
i<n;i++)
{
ttur +=p[i].ttime; twat +=
p[i].wtime;
}
awat = (float)twat /n; atur =
(float)ttur /n;
printf("\n FCFSScheduling\n\n");
for(i=0; i<28; i++)
printf("-");
printf("\nProcess B-Time T-Time W-Time\n"); for(i=0; i<28;
i++)
printf("-");
for(i=0; i<n; i++)
printf("\n P%d\t%4d\t%3d\t%2d",
p[i].pid,p[i].btime,p[i].ttime,p[i].wtime);
printf("\n"); for(i=0; i<28;
i++)
printf("-");
printf("\n\nGANTTChart\n"); printf("-
");
for(i=0; i<(p[n-1].ttime + 2*n); i++) printf("-");
printf("\n");
printf("|"); for(i=0; i<n;
i++)
{
k = p[i].btime/2; for(j=0;
j<k;j++)
printf(" "); printf("P%d",p[i].pid);
for(j=k+1; j<p[i].btime;j++)
printf(" ");
printf("|");
}
printf("\n");
printf("-");
for(i=0; i<(p[n-1].ttime + 2*n); i++) printf("-");
printf("\n");
printf("0"); for(i=0; i<n;
i++)
{
for(j=0; j<p[i].btime;j++) printf(" ");
printf("%2d",p[i].ttime);
}
}
Output
$ gcc fcfs.c
$ ./a.out
Enter no. of process : 4
Burst time for process P1 (in ms) : 10 Burst time for
process P2 (in ms) : 4 Burst time for process P3 (in
ms) : 11 Burst time for process P4 (in ms) : 6
FCFS Scheduling
----------------------------
Process B-Time T-TimeW-Time
----------------------------
P1 10 10 0
P2 4 14 10
P3 11 25 14
P4 6 31 25
----------------------------
GANTT Chart
----------------------------------------
| P1 | P2 | P3 | P4 |
---------------------------------------- 0 10 14
25 31
Ex. No. 8 Tree Traversal
Program
/* Tree Traversal */
#include <stdio.h>
#include<stdlib.h>
typedef structnode
{
int data;
struct node *left; struct
node*right;
}node;
int count=1;
main()
{
node *root =NULL;
int digit;
puts("Enter integer:To quit enter 0");
scanf("%d", &digit);
while(digit != 0)
{
root=insert(root,digit);
scanf("%d",&digit);
}
printf("\nThe preorder traversal of tree is:\n");
preorder(root);
printf("\nThe inorder traversal of tree is:\n");
inorder(root);
printf("\nThe postorder traversal of tree is:\n");
postorder(root);
getch();
}
Output
Enter integer:To quit enter0 12 4 6 9 14
17 3 19 0
Program
#include <stdio.h>
#include<stdlib.h>
struct node
{
int key;
struct node *left;
struct node*right;
};
main()
{
struct node *root =NULL;
root = insert(root, 50);
root = insert(root, 30);
root = insert(root, 20);
root = insert(root, 40);
root = insert(root, 70);
root = insert(root, 60);
root = insert(root,80);
printf("Inorder traversal of the given tree \n");
inorder(root);
printf("\nDelete 20\n"); r
oot = deleteNode(root,20);
printf("Inorder traversal of the modified tree \n");
inorder(root);
printf("\nDelete 30\n");
root = deleteNode(root,30);
printf("Inorder traversal of the modified tree \n");
inorder(root);
printf("\nDelete 50\n");
root = deleteNode(root, 50);
printf("Inorder traversal of the modified tree \n");
inorder(root);
}
Output
.
Ex. No. 10a Linear Search
Date:
Program
#include <stdio.h>
#include<conio.h>
main()
{
int a[50],i, n, val,found;
clrscr();
printf("Enter number of elements : ");
scanf("%d", &n);
printf("Enter Array Elements : \n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
Program
#include <stdio.h>
#include<conio.h>
main()
{
int a[50],i, n, upper, lower, mid, val, found;
clrscr();
printf("Enter array size : ");
scanf("%d", &n);
for(i=0; i<n;i++)
a[i] = 2 * i;
printf("\n Elements in Sorted Order \n");
for(i=0; i<n; i++)
printf("%4d", a[i]);
printf("\n Enter element to locate : ");
scanf("%d", &val);
upper = n; lower
= 0;
found = -1;
while (lower <= upper)
{
mid = (upper +lower)/2;
if (a[mid] == val)
{
printf("Located at position %d", mid);
found = 1;
break;
}
else if(a[mid] >val)
upper = mid - 1;
else
lower = mid + 1;
}
Program
/* Bubble Sort */
#include<stdio.h>
#include<conio.h>
main()
{
int a[50],i, j, n,t; clrscr();
printf("Enter number of elements : ");
scanf("%d", &n);
printf("Enter Array Elements \n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
Output
Program
/* Quick Sort */
#include<stdio.h>
#include<conio.h>
void qsort(int arr[20],
int fst, int last);
main()
{
int arr[30];
int i, size;
printf("Enter total no. of the elements : ");
scanf("%d", &size);
printf("Enter total %d elements : \n", size);
for(i=0; i<size; i++)
scanf("%d",&arr[i]);
qsort(arr,0,size-1);
printf("\n Quick sorted elements \n");
for(i=0; i<size; i++)
printf("%d\t",arr[i]);
getch();
}
void qsort(int arr[20], int fst, int last)
{
int i, j, pivot,tmp;
if(fst < last)
{
pivot = fst; i = fst;
j = last;
while(i < j)
{
while(arr[i] <=arr[pivot] && i<last)
i++;
while(arr[j] >arr[pivot])
j--;
if(i <j )
{
tmp = arr[i];
arr[i] =arr[j];
arr[j] = tmp;
}}
tmp = arr[pivot];
arr[pivot] = arr[j];
arr[j] = tmp;
qsort(arr, fst, j-1);
qsort(arr, j+1,last);
}}
Output
Program
/* Merge sort */
#include<stdio.h>
#include<conio.h>
main()
{
int i, arr[30];
printf("Enter total no. of elements : ");
scanf("%d", &size);
printf("Enter array elements : ");
for(i=0; i<size; i++)
scanf("%d", &arr[i]);
part(arr, 0,size-1);
printf("\n Merge sorted list : ");
for(i=0; i<size; i++)
printf("%d",arr[i]);
getch();
}
}
}
if(j > mid)
{
for(k=m; k<=max; k++)
{
tmp[i] =arr[k]; i++;
}
}
else
{
for(k=j; k<=mid; k++)
{
tmp[i] =arr[k]; i++;
}
}
for(k=min; k<=max;k++) arr[k]
= tmp[k];
}
Output
Program
p++;
printf("\n After Pass %d: ", p);
for(k=0; k<n; k++)
printf(" %d", a[k]);
}
Program
/* Open hashing */
#include <stdio.h>
#include<stdlib.h>