Monthly Archives: December 2017


Write an algorithm and program for implementation of multiple stacks in an Array – IGNOU BCA Assignment 2017 – 18

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-033
Course Title : Data and File Structures Lab
Assignment Number : BCA(3)/L-033/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write an algorithm and program for implementation of multiple stacks in an Array – IGNOU BCA Assignment 2017 – 18

 

CODE:

#include <stdio.h>
#define max 10

int top1, top2, stk_arr[max];

void push();
void pop();
void display();

void main()
{
int ch;
top1=-1,top2=max;
do
{
printf(“\n 1:push\n 2:pop\n 3:display\n 4:exit\n choice:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:printf(“exiting from program\n”);
break;
default:printf(“wrong choice\n”);
break;
}
}while(ch!=4);
}
void push()
{
int x,ch;
if(top1==top2-1)
{
printf(“stack overflow \n”);
return;
}
printf(“enter a no \n”);
scanf(“%d”,&x);
printf(“\n press 1 to push in stack1 or press 2 for stack2:”);
scanf(“%d”,&ch);
if(ch==1)
stk_arr[++top1]=x;
else
stk_arr[--top2]=x;
printf(“\n %d element is successfully pushed \n”,x);
return;
}

void pop()
{
int y,ch;
printf(“\n press 1 to pop from stack1 or press 2 for stack2″);
scanf(“%d”,&ch);
if(ch==1)
{
if(top1==-1)
{
printf(“stack underflow\n”);
return;
}
y=stk_arr[top1];
stk_arr[top1--]=0;
}
else
{
if(top2==max)
{
printf(“stack underflow\n”);
return;
}
y=stk_arr[top2];
stk_arr[top2++]=0;
}
printf(“\n%d element is successfully poped from stack \n”, y);
return;
}

void display()
{
int i;
if (top1 == -1)
{
printf(“stack 1 is empty \n”);
}
else
{
printf(“elements of Stack 1 are : \n”);
for (i = 0; i <= top1; i++)
{
printf(“%d\n”,stk_arr[i]);
}
}
if (top2 == max)
{
printf(“stack 2 is empty \n”);
}
else
{
printf(“elements of Stack 2 are : \n”);
for (i = max; i >= top2; i–)
{
printf(“%d\n”,stk_arr[i]);
}
}
return ;
}

 

#include <stdio.h>
#define max 10
int top1, top2, stk_arr[max];
void push();
void pop();
void display();
void main()
{
int ch;
top1=-1,top2=max;
do
{
printf("\n 1:push\n 2:pop\n 3:display\n 4:exit\n choice:");
scanf("%d", &ch);
switch (ch)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:printf("exiting from program\n");
break;
default:printf("wrong choice\n");
break;
}
}while(ch!=4);
}
void push()
{
int x,ch;
if(top1==top2-1)
{
printf("stack overflow \n");
return;
}
printf("enter a no \n");
scanf("%d",&x);
printf("\n press 1 to push in stack1 or press 2 for stack2:");
scanf("%d",&ch);
if(ch==1)
stk_arr[++top1]=x;
else
stk_arr[--top2]=x;
printf("\n %d element is successfully pushed \n",x);
return;
}
void pop()
{
int y,ch;
printf("\n press 1 to pop from stack1 or press 2 for stack2");
scanf("%d",&ch);
if(ch==1)
{
if(top1==-1)
{
printf("stack underflow\n");
return;
}
y=stk_arr[top1];
stk_arr[top1--]=0;
}
else
{
if(top2==max)
{
printf("stack underflow\n");
return;
}
y=stk_arr[top2];
stk_arr[top2++]=0;
}
printf("\n%d element is successfully poped from stack \n", y);
return;
}
void display()
{
int i;
if (top1 == -1)
{
printf("stack 1 is empty \n");
}
else
{
printf("elements of Stack 1 are : \n");
for (i = 0; i <= top1; i++)
{
printf("%d\n",stk_arr[i]);
}
}
if (top2 == max)
{
printf("stack 2 is empty \n");
}
else
{
printf("elements of Stack 2 are : \n");
for (i = max; i >= top2; i--)
{
printf("%d\n",stk_arr[i]);
}
}
return ;
}

 

SCREENSHOTS:

C_program_Multiple_Stack_on_Array

C_program_Multiple_Stack_on_Array_Out

Write an algorithm and program that accepts a Binary Tree as Input and Checks if the input Binary tree is Complete Binary Tree or a Full Binary Tree – IGNOU BCA Assignment 2017 – 18

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-033
Course Title : Data and File Structures Lab
Assignment Number : BCA(3)/L-033/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write an algorithm and program that accepts a Binary Tree as Input and Checks if the input Binary tree is Complete Binary Tree or a Full Binary Tree and prints appropriate message – IGNOU BCA Assignment 2017 – 18

 

CODE:

#include<stdio.h>
#include<stdlib.h>

/* Tree node structure */
struct Node
{
int key;
struct Node *left, *right;
};

/* This function counts the number of nodes in a binary tree */
int countNodes(struct Node* root)
{
if (root == NULL)
return (0);
return (1 + countNodes(root->left) + countNodes(root->right));
}

/* This function checks if the binary tree is complete or not */
int isComplete (struct Node* root, int index,int number_nodes)
{
// An empty tree is complete
if (root == NULL)
return (1);

// If index assigned to current node is more than
// number of nodes in tree, then tree is not complete
if (index >= number_nodes)
return (0);

// Recur for left and right subtrees
return (isComplete(root->left, 2*index + 1, number_nodes) &&
isComplete(root->right, 2*index + 2, number_nodes));
}
/* Helper function that allocates a new node with the
given key and NULL left and right pointer. */
struct Node *newNode(char k)
{
struct Node *node = (struct Node*)malloc(sizeof(struct Node));
node->key = k;
node->right = node->left = NULL;
return node;
}

/* This function tests if a binary tree is a full binary tree. */
int isFullTree (struct Node* root)
{
// If empty tree
if (root == NULL)
return (1);

// If leaf node
if (root->left == NULL && root->right == NULL)
return (1);

// If both left and right are not NULL, and left & right subtrees
// are full
if ((root->left) && (root->right))
return (isFullTree(root->left) && isFullTree(root->right));

// We reach here when none of the above if conditions work
return (0);
}

// Driver Program
void main()
{
struct Node* root = NULL;
unsigned int node_count;
unsigned int index;

clrscr();
root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);

root->left->right = newNode(40);
root->left->left = newNode(50);
root->right->left = newNode(60);
root->right->right = newNode(70);

root->left->left->left = newNode(80);
root->left->left->right = newNode(90);
root->left->right->left = newNode(80);
root->left->right->right = newNode(90);
root->right->left->left = newNode(80);
root->right->left->right = newNode(90);
root->right->right->left = newNode(80);
root->right->right->right = newNode(90);

node_count = countNodes(root);
index = 0;

if (isComplete(root, index, node_count))
printf(“\nThe Binary Tree is complete\n”);
else
printf(“\nThe Binary Tree is not complete\n”);

if (isFullTree(root))
printf(“\nThe Binary Tree is full\n”);
else
printf(“\nThe Binary Tree is not full\n”);

getch();

#include<stdio.h>
#include<stdlib.h>
/* Tree node structure */
struct Node
{
int key;
struct Node *left, *right;
};
/* This function counts the number of nodes in a binary tree */
int countNodes(struct Node* root)
{
if (root == NULL)
return (0);
return (1 + countNodes(root->left) + countNodes(root->right));
}
/* This function checks if the binary tree is complete or not */
int isComplete (struct Node* root, int index,int number_nodes)
{
// An empty tree is complete
if (root == NULL)
return (1);
// If index assigned to current node is more than
// number of nodes in tree, then tree is not complete
if (index >= number_nodes)
return (0);
// Recur for left and right subtrees
return (isComplete(root->left, 2*index + 1, number_nodes) &&
isComplete(root->right, 2*index + 2, number_nodes));
}
/* Helper function that allocates a new node with the
given key and NULL left and right pointer. */
struct Node *newNode(char k)
{
struct Node *node = (struct Node*)malloc(sizeof(struct Node));
node->key = k;
node->right = node->left = NULL;
return node;
}
/* This function tests if a binary tree is a full binary tree. */
int isFullTree (struct Node* root)
{
// If empty tree
if (root == NULL)
return (1);
// If leaf node
if (root->left == NULL && root->right == NULL)
return (1);
// If both left and right are not NULL, and left & right subtrees
// are full
if ((root->left) && (root->right))
return (isFullTree(root->left) && isFullTree(root->right));
// We reach here when none of the above if conditions work
return (0);
}
// Driver Program
void main()
{
struct Node* root = NULL;
unsigned int node_count;
unsigned int index;
clrscr();
root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->right = newNode(40);
root->left->left = newNode(50);
root->right->left = newNode(60);
root->right->right = newNode(70);
root->left->left->left = newNode(80);
root->left->left->right = newNode(90);
root->left->right->left = newNode(80);
root->left->right->right = newNode(90);
root->right->left->left = newNode(80);
root->right->left->right = newNode(90);
root->right->right->left = newNode(80);
root->right->right->right = newNode(90);
node_count = countNodes(root);
index = 0;
if (isComplete(root, index, node_count))
printf("\nThe Binary Tree is complete\n");
else
printf("\nThe Binary Tree is not complete\n");
if (isFullTree(root))
printf("\nThe Binary Tree is full\n");
else
printf("\nThe Binary Tree is not full\n");
getch();

 

SCREENSHOTS:

C_program_Check_Full_Complete_BST

C_program_Check_Full_Complete_BST_Out

Write an algorithm for the implementation of a Doubly Linked List – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCS-021
Course Title : Data and File Structures
Assignment Number : MCA(2)/021/Assignment/17-18
Maximum Marks : 100
Weightage : 25%

Write an algorithm for the implementation of a Doubly Linked List – IGNOU MCA Assignment 2017 – 18

CODE:

#include<stdio.h>
struct node
{
int data;
struct node *next;
struct node *prev;
};
typedef struct node node; //with this Use “node” instead of “struct node”
node *root=NULL; //Global variable “root” pointer
node *create_node(int); //Declaration
void insert(int); //Declaration
void display_list(node *); //Declaration

void main()
{
clrscr();
display_list(root);
insert(10);
insert(20);
insert(30);
insert(40);
display_list(root);
getch();
}

node *create_node(int x)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->data=x;
temp->next=NULL;
temp->prev=NULL;
return temp;
}

void insert(int x)
{
node *start;
start=root;
if(root==NULL)
{ root=create_node(x);root->next=root;root->prev=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x);
start->next->next=root;
start->next->prev=start;
}
}
void display_list(node *start)
{
printf(“\nLink List :-\n”);
if(start==NULL)
{ printf(“List is Empty!\n”); }
else
{
while(start->next!=root)
{ printf(“%d->”,start->data);
start=start->next;
}printf(“%d->”,start->data);
}
}

 

#include<stdio.h>
struct node
{
int data;
struct node *next;
struct node *prev;
};
typedef struct node node; //with this Use "node" instead of "struct node"
node *root=NULL; //Global variable "root" pointer
node *create_node(int); //Declaration
void insert(int); //Declaration
void display_list(node *); //Declaration
void main()
{
clrscr();
display_list(root);
insert(10);
insert(20);
insert(30);
insert(40);
display_list(root);
getch();
}
node *create_node(int x)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->data=x;
temp->next=NULL;
temp->prev=NULL;
return temp;
}
void insert(int x)
{
node *start;
start=root;
if(root==NULL)
{ root=create_node(x);root->next=root;root->prev=root;}
else
{
while(start->next!=root)
{
start=start->next;
} start->next=create_node(x);
start->next->next=root;
start->next->prev=start;
}
}
void display_list(node *start)
{
printf("\nLink List :-\n");
if(start==NULL)
{ printf("List is Empty!\n"); }
else
{
while(start->next!=root)
{ printf("%d->",start->data);
start=start->next;
}printf("%d->",start->data);
}
}

 

SCREENSHOTS:

C_program_Doubly_Linked_List

C_program_Doubly_Linked_List_Output

Write an algorithm for the implementation of an AVL tree – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCS-021
Course Title : Data and File Structures
Assignment Number : MCA(2)/021/Assignment/17-18
Maximum Marks : 100
Weightage : 25%

Write an algorithm for the implementation of an AVL tree – IGNOU MCA Assignment 2017 – 18

CODE:

#include <stdio.h>
#include <stdlib.h>

struct avl_node_s {
struct avl_node_s *left;
struct avl_node_s *right;
int value;
};

typedef struct avl_node_s avl_node_t;

struct avl_tree_s {
struct avl_node_s *root;
};

typedef struct avl_tree_s avl_tree_t;
/* Create a new AVL tree. */
avl_tree_t *avl_create() {
avl_tree_t *tree = NULL;

if( ( tree = malloc( sizeof( avl_tree_t ) ) ) == NULL ) {
return NULL;
}

tree->root = NULL;

return tree;
}

/* Initialize a new node. */
avl_node_t *avl_create_node() {
avl_node_t *node = NULL;

if( ( node = malloc( sizeof( avl_node_t ) ) ) == NULL ) {
return NULL;
}

node->left = NULL;
node->right = NULL;
node->value = 0;

return node;
}

/* Insert a new node. */
void avl_insert( avl_tree_t *tree, int value ) {
avl_node_t *node = NULL;
avl_node_t *next = NULL;
avl_node_t *last = NULL;

/* Well, there must be a first case */
if( tree->root == NULL ) {
node = avl_create_node();
node->value = value;

tree->root = node;

/* Okay. We have a root already. Where do we put this? */
} else {
next = tree->root;
last = NULL;

while( next != NULL ) {
last = next;

if( value < next->value ) {
next = next->left;

} else if( value > next->value ) {
next = next->right;

/* Have we already inserted this node? */
} else if( value == next->value ) {
/* This shouldn’t happen. */
}
}

node = avl_create_node();
node->value = value;

if( value < last->value ) last->left = node;
if( value > last->value ) last->right = node;
}

}

/* Find the height of an AVL node recursively */
int avl_node_height( avl_node_t *node ) {
int height_left = 0;
int height_right = 0;

if( node->left ) height_left = avl_node_height( node->left );
if( node->right ) height_right = avl_node_height( node->right );

return height_right > height_left ? ++height_right : ++height_left;
}

/* Find the balance of an AVL node */
int avl_node_balance( avl_node_t *node ) {
int balance = 0;
if( node->left ) balance += avl_node_height( node->left );
if( node->right ) balance -= avl_node_height( node->right );

return balance;
}

/* Do a depth first traverse of a node. */
void avl_traverse_node_dfs( avl_node_t *node, int depth ) {
int i = 0;

if( node->left ) avl_traverse_node_dfs( node->left, depth + 2 );

for( i = 0; i < depth; i++ ) putchar( ‘ ‘ );
printf( “%d: %d\n”, node->value, avl_node_balance( node ) );

if( node->right ) avl_traverse_node_dfs( node->right, depth + 2 );
}

/* Do a depth first traverse of a tree. */
void avl_traverse_dfs( avl_tree_t *tree ) {

avl_traverse_node_dfs( tree->root, 0 );
}

void main()
{
avl_tree_t *tree = NULL;
clrscr();
tree = avl_create();

avl_insert( tree, 30 );
avl_insert( tree, 20 );
avl_insert( tree, 40 );
avl_insert( tree, 10 );
avl_insert( tree, 50 );

avl_traverse_dfs( tree );

getch();
}

 

#include <stdio.h>
#include <stdlib.h>
struct avl_node_s {
struct avl_node_s *left;
struct avl_node_s *right;
int value;
};
typedef struct avl_node_s avl_node_t;
struct avl_tree_s {
struct avl_node_s *root;
};
typedef struct avl_tree_s avl_tree_t;
/* Create a new AVL tree. */
avl_tree_t *avl_create() {
avl_tree_t *tree = NULL;
if( ( tree = malloc( sizeof( avl_tree_t ) ) ) == NULL ) {
return NULL;
}
tree->root = NULL;
return tree;
}
/* Initialize a new node. */
avl_node_t *avl_create_node() {
avl_node_t *node = NULL;
if( ( node = malloc( sizeof( avl_node_t ) ) ) == NULL ) {
return NULL;
}
node->left = NULL;
node->right = NULL;
node->value = 0;
return node;
}
/* Insert a new node. */
void avl_insert( avl_tree_t *tree, int value ) {
avl_node_t *node = NULL;
avl_node_t *next = NULL;
avl_node_t *last = NULL;
/* Well, there must be a first case */
if( tree->root == NULL ) {
node = avl_create_node();
node->value = value;
tree->root = node;
/* Okay. We have a root already. Where do we put this? */
} else {
next = tree->root;
last = NULL;
while( next != NULL ) {
last = next;
if( value < next->value ) {
next = next->left;
} else if( value > next->value ) {
next = next->right;
/* Have we already inserted this node? */
} else if( value == next->value ) {
/* This shouldn't happen. */
}
}
node = avl_create_node();
node->value = value;
if( value < last->value ) last->left = node;
if( value > last->value ) last->right = node;
}
}
/* Find the height of an AVL node recursively */
int avl_node_height( avl_node_t *node ) {
int height_left = 0;
int height_right = 0;
if( node->left ) height_left = avl_node_height( node->left );
if( node->right ) height_right = avl_node_height( node->right );
return height_right > height_left ? ++height_right : ++height_left;
}
/* Find the balance of an AVL node */
int avl_node_balance( avl_node_t *node ) {
int balance = 0;
if( node->left ) balance += avl_node_height( node->left );
if( node->right ) balance -= avl_node_height( node->right );
return balance;
}
/* Do a depth first traverse of a node. */
void avl_traverse_node_dfs( avl_node_t *node, int depth ) {
int i = 0;
if( node->left ) avl_traverse_node_dfs( node->left, depth + 2 );
for( i = 0; i < depth; i++ ) putchar( ' ' );
printf( "%d: %d\n", node->value, avl_node_balance( node ) );
if( node->right ) avl_traverse_node_dfs( node->right, depth + 2 );
}
/* Do a depth first traverse of a tree. */
void avl_traverse_dfs( avl_tree_t *tree ) {
avl_traverse_node_dfs( tree->root, 0 );
}
void main()
{
avl_tree_t *tree = NULL;
clrscr();
tree = avl_create();
avl_insert( tree, 30 );
avl_insert( tree, 20 );
avl_insert( tree, 40 );
avl_insert( tree, 10 );
avl_insert( tree, 50 );
avl_traverse_dfs( tree );
getch();
}

 

SCREENSHOTS:

C_program_Avl_Tree

C_program_Avl_Tree_Output

Write an algorithm that accepts a Tree as input and prints the correspondingBinary Tree – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCS-021
Course Title : Data and File Structures
Assignment Number : MCA(2)/021/Assignment/17-18
Maximum Marks : 100
Weightage : 25%

Write an algorithm that accepts a Tree as input and prints the correspondingBinary Tree – IGNOU MCA Assignment 2017 – 18

CODE:

#include <stdio.h>
#include <stdlib.h>
struct tnode
{
int data;
struct tnode *lchild, *rchild;
};

struct tnode *insert(struct tnode *p,int val)
{
struct tnode *temp1,*temp2;
if(p == NULL)
{
p = (struct tnode *) malloc(sizeof(struct tnode));
/* insert the new node as root node*/
if(p == NULL)
{
printf(“Cannot allocate\n”);
exit(0);
}
p->data = val;
p->lchild=p->rchild=NULL;
}
else
{
temp1 = p;
/* traverse the tree to get a pointer to that node
whose child will be the newly created node*/
while(temp1 != NULL)
{
temp2 = temp1;
if( temp1 ->data > val)
temp1 = temp1->lchild;
else
temp1 = temp1->rchild;
}
if( temp2->data > val)
{
temp2->lchild = (struct tnode*)malloc(sizeof(struct tnode));
/*inserts the newly created node as left child*/
temp2 = temp2->lchild;
if(temp2 == NULL)
{
printf(“Cannot allocate\n”);
exit(0);
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
else
{
temp2->rchild = (struct tnode*)malloc(sizeof(struct tnode));
/*inserts the newly created node as left child*/
temp2 = temp2->rchild;
if(temp2 == NULL)
{
printf(“Cannot allocate\n”);
exit(0);
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
}
return(p);
}
/* a function to binary tree in preorder */
void preorder(struct tnode *p)
{
if(p != NULL)
{
printf(“%d\t”,p->data);
preorder(p->lchild);
preorder(p->rchild);
}
}
/* a function to binary tree in inorder */
void inorder(struct tnode *p)
{
if(p != NULL)
{
inorder(p->lchild);
printf(“%d\t”,p->data);
inorder(p->rchild);
}
}
/* a function to binary tree in postorder */
void postorder(struct tnode *p)
{
if(p != NULL)
{
postorder(p->lchild);
postorder(p->rchild);
printf(“%d\t”,p->data);
}
}
void main()
{
struct tnode *root = NULL;
int n,x;
clrscr();
printf(“\nEnter the number of nodes\n”);
scanf(“%d”,&n);
while(n!=0)
{
printf(“Enter the data value\n”);
scanf(“%d”,&x);
root = insert(root,x);
n–;
}
printf(“\n**THIS TREE IS BINARY TREE**\n”);

printf(“\nPREORDER OF TREE : \n”);
preorder(root);
printf(“\nINORDER OF TREE : \n”);
inorder(root);
printf(“\nPOSTORDER OF TREE : \n”);
postorder(root);
getch();

}

 

#include <stdio.h>
#include <stdlib.h>
struct tnode
{
int data;
struct tnode *lchild, *rchild;
};
struct tnode *insert(struct tnode *p,int val)
{
struct tnode *temp1,*temp2;
if(p == NULL)
{
p = (struct tnode *) malloc(sizeof(struct tnode));
/* insert the new node as root node*/
if(p == NULL)
{
printf("Cannot allocate\n");
exit(0);
}
p->data = val;
p->lchild=p->rchild=NULL;
}
else
{
temp1 = p;
/* traverse the tree to get a pointer to that node
whose child will be the newly created node*/
while(temp1 != NULL)
{
temp2 = temp1;
if( temp1 ->data > val)
temp1 = temp1->lchild;
else
temp1 = temp1->rchild;
}
if( temp2->data > val)
{
temp2->lchild = (struct tnode*)malloc(sizeof(struct tnode));
/*inserts the newly created node as left child*/
temp2 = temp2->lchild;
if(temp2 == NULL)
{
printf("Cannot allocate\n");
exit(0);
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
else
{
temp2->rchild = (struct tnode*)malloc(sizeof(struct tnode));
/*inserts the newly created node as left child*/
temp2 = temp2->rchild;
if(temp2 == NULL)
{
printf("Cannot allocate\n");
exit(0);
}
temp2->data = val;
temp2->lchild=temp2->rchild = NULL;
}
}
return(p);
}
/* a function to binary tree in preorder */
void preorder(struct tnode *p)
{
if(p != NULL)
{
printf("%d\t",p->data);
preorder(p->lchild);
preorder(p->rchild);
}
}
/* a function to binary tree in inorder */
void inorder(struct tnode *p)
{
if(p != NULL)
{
inorder(p->lchild);
printf("%d\t",p->data);
inorder(p->rchild);
}
}
/* a function to binary tree in postorder */
void postorder(struct tnode *p)
{
if(p != NULL)
{
postorder(p->lchild);
postorder(p->rchild);
printf("%d\t",p->data);
}
}
void main()
{
struct tnode *root = NULL;
int n,x;
clrscr();
printf("\nEnter the number of nodes\n");
scanf("%d",&n);
while(n!=0)
{
printf("Enter the data value\n");
scanf("%d",&x);
root = insert(root,x);
n--;
}
printf("\n**THIS TREE IS BINARY TREE**\n");
printf("\nPREORDER OF TREE : \n");
preorder(root);
printf("\nINORDER OF TREE : \n");
inorder(root);
printf("\nPOSTORDER OF TREE : \n");
postorder(root);
getch();
}

 

SCREENSHOTS:

C_program_Tree_2_bin_tree

C_program_Tree_2_bin_tree_Output

An 8086 assembly language program that finds the sum of 10 consecutive byte values stored in an array in the memory. The result should be stored in AX register – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write and run (using appropriate calling program) a near procedure in 8086 assembly language that accepts an ASCII value as a parameter in AL register and displays this value on the output screen – IGNOU MCA Assignment 2017 - 18

Code:-

DATA SEGMENT
ARR DB 5,3,7,1,9,2,6,8,4,10
LEN DW $-ARR
SUM DW ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA SI,ARR
MOV AX,0
MOV CX,LEN
REPEAT:
MOV BL,ARR[SI]
MOV BH,0
ADD AX,BX

INC SI
LOOP REPEAT

MOV SUM,AX

MOV AH,4CH
INT 21H
CODE ENDS
END START

DATA SEGMENT
ARR DB 5,3,7,1,9,2,6,8,4,10
LEN DW $-ARR
SUM DW ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AX,0
MOV CX,LEN
REPEAT:
MOV BL,ARR[SI]
MOV BH,0
ADD AX,BX
INC SI
LOOP REPEAT
MOV SUM,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START

Screen Shots :-

Asm_program_Sum_in_Array

Before Execution :-

Asm_program_Sum_in_Array_v1

After Execution :-

Asm_program_Sum_in_Array_v2

Note :- To see the variable and its value you have to click vars button in the emulator.

An near procedure in 8086 assembly language that accepts an ASCII value as a parameter in AL register and displays this value on the output screen – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write and run (using appropriate calling program) a near procedure in 8086 assembly language that accepts an ASCII value as a parameter in AL register and displays this value on the output screen – IGNOU MCA Assignment 2017 - 18

Code:-

DATA SEGMENT
MSG1 DB 10,13,”ENTER ANY ASCII VALUE : $”
MSG2 DB 10,13,”PRINTING AL VALUE : $”
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H

CALL PRINT_AL

MOV AH,4CH
INT 21H
CODE ENDS

PRINT_AL PROC NEAR

MOV AH,1
INT 21H
MOV BL,AL

LEA DX,MSG2
MOV AH,9
INT 21H

MOV DL,BL
MOV AH,2
INT 21H

RET
PRINT_AL ENDP
END START

DATA SEGMENT
MSG1 DB 10,13,"ENTER ANY ASCII VALUE : $"
MSG2 DB 10,13,"PRINTING AL VALUE : $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
CALL PRINT_AL
MOV AH,4CH
INT 21H
CODE ENDS
PRINT_AL PROC NEAR
MOV AH,1
INT 21H
MOV BL,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV DL,BL
MOV AH,2
INT 21H
RET
PRINT_AL ENDP
END START

Screen Shots :-

Asm_program_Proc_AL_2_Screen

After Execution :-

Asm_program_Proc_AL_2_Screen_Output

Note :- To see the variable and its value you have to click vars button in the emulator.

Write and run an Assembly language program that converts an ASCII string containing decimal digits, stored in three consecutive locations in the memory into equivalent binary number – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write and run an Assembly language program that converts an ASCII string containing decimal digits, stored in three consecutive locations in the memory into equivalent binary number. You may assume that the three locations contains ASCII equivalent of digit 3, digit 4 and digit 5. The output of this program should be stored in AX register  - IGNOU MCA Assignment 2017 – 18

Code:-

DATA SEGMENT
ARR DB ’3′,’4′,’5′
HUN DB ?
TEN DB ?
UNT DB ?
LEN DW $-ARR
RES DW ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA SI,ARR

MOV AL,ARR[SI]
SUB AL,30H
MOV HUN,AL
INC SI

MOV AL,ARR[SI]
SUB AL,30H
MOV TEN,AL
INC SI

MOV AL,ARR[SI]
SUB AL,30H
MOV UNT,AL

MOV AX,0
MOV CL,100
MOV AL,HUN
MUL CL
MOV BX,AX

MOV AX,0
MOV CL,10
MOV AL,TEN
MUL CL

ADD AX,BX

MOV BX,0
MOV BL,UNT
ADD AX,BX

MOV RES,AX

MOV AH,4CH
INT 21H
CODE ENDS
END START

DATA SEGMENT
ARR DB '3','4','5'
HUN DB ?
TEN DB ?
UNT DB ?
LEN DW $-ARR
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
SUB AL,30H
MOV HUN,AL
INC SI
MOV AL,ARR[SI]
SUB AL,30H
MOV TEN,AL
INC SI
MOV AL,ARR[SI]
SUB AL,30H
MOV UNT,AL
MOV AX,0
MOV CL,100
MOV AL,HUN
MUL CL
MOV BX,AX
MOV AX,0
MOV CL,10
MOV AL,TEN
MUL CL
ADD AX,BX
MOV BX,0
MOV BL,UNT
ADD AX,BX
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START

Screen Shots :-

Asm_program_Ascii _3digit_To_Binary

Before Execution :-

Asm_program_Ascii _3digit_To_Binary_v1

After Execution :-

Asm_program_Ascii _3digit_To_Binary_v2

Note :- To see the variable and its value you have to click vars button in the emulator.

An assembly near procedure which converts the packed BCDdigits to equivalent binary number – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write a program in 8086 assembly Language that passes a byte containing two packed BCD digits, as parameter to anear procedure named TOBINARY, which converts the packed BCDdigits to equivalent binary number. This binary number is returned tothe calling assembly program – IGNOU MCA Assignment 2017 – 18

Code:-

DATA SEGMENT
PACKEDBCD DB 52H
BINARY DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

MOV AH,0
MOV AL,PACKEDBCD

CALL TOBINARY

MOV BINARY,AL

MOV AH,4CH
INT 21H
CODE ENDS

TOBINARY PROC NEAR

MOV BL,AL

AND AL,0F0H
AND BL,0FH

MOV CL,04H
ROL AL,CL

MOV CL,10
MUL CL

ADD AL,BL
RET
TOBINARY ENDP

END START

DATA SEGMENT
PACKEDBCD DB 52H
BINARY DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AH,0
MOV AL,PACKEDBCD
CALL TOBINARY
MOV BINARY,AL
MOV AH,4CH
INT 21H
CODE ENDS
TOBINARY PROC NEAR
MOV BL,AL
AND AL,0F0H
AND BL,0FH
MOV CL,04H
ROL AL,CL
MOV CL,10
MUL CL
ADD AL,BL
RET
TOBINARY ENDP
END START

Screen Shots :-

Asm_program_Proc_Packed_BCD_to_Binary

Before Execution :-

Asm_program_Proc_Packed_BCD_to_Binary_v1

After Execution :-

Asm_program_Proc_Packed_BCD_to_Binary_v2

Note :- To see the variable and its value you have to click vars button in the emulator.

An Assembly language program that converts an ASCII string containing decimal digits into equivalent binary number – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write and run an Assembly language program that converts an ASCII string containing decimal digits, stored in three consecutive locations in the memory into equivalent binary number. You may assume that the three locations contains ASCII equivalent of digit 3, digit 4 and digit 5. The output of this program should be stored in AX register – IGNOU MCA Assignment 2017 – 18

Code:-

DATA SEGMENT
MSG1 DB 10,13,’ENTER ANY STRING :- $’
MSG2 DB 10,13,’ENTERED STRING IS : $’
MSG3 DB 10,13,’ENTERED DATA IS NOT ALPABETS ! $’
MSG4 DB 10,13,’ENTERED DATA NOT A 4 DIGIT VALUE ! $’
MSG5 DB 10,13,’UPPER CASE OF STRING IS :- $’

FLAG DB 0H

P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP (‘$’)
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

LEA DX,P1
MOV AH,0AH
INT 21H

DISPLAY MSG2
DISPLAY P11

CHECK1: CMP L1,04H
JNE NOT4D

LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL

CHECK2:
CMP [SI],41H
JB INCFLAG
CMP [SI],7BH
JB NOINC
INCFLAG:
INC FLAG
NOINC:

INC SI
LOOP CHECK2

CHECK3: CMP FLAG,0H
JNE NOTALP

CONV:
LEA SI,P11

MOV CL,L1
MOV CH,0
CHECK4:
CMP [SI],61H
JB DONE1

CMP [SI],5BH

UPR: SUB [SI],20H

DONE1: INC SI
LOOP CHECK4

DISPLAY MSG5
DISPLAY P11

JMP DONE
NOTALP:
DISPLAY MSG3
JMP DONE

NOT4D:
DISPLAY MSG4

DONE:

MOV AH,4CH
INT 21H
CODE ENDS

END START

DATA SEGMENT
MSG1 DB 10,13,'ENTER ANY STRING :- $'
MSG2 DB 10,13,'ENTERED STRING IS : $'
MSG3 DB 10,13,'ENTERED DATA IS NOT ALPABETS ! $'
MSG4 DB 10,13,'ENTERED DATA NOT A 4 DIGIT VALUE ! $'
MSG5 DB 10,13,'UPPER CASE OF STRING IS :- $'
FLAG DB 0H
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY MSG2
DISPLAY P11
CHECK1: CMP L1,04H
JNE NOT4D
LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL
CHECK2:
CMP [SI],41H
JB INCFLAG
CMP [SI],7BH
JB NOINC
INCFLAG:
INC FLAG
NOINC:
INC SI
LOOP CHECK2
CHECK3: CMP FLAG,0H
JNE NOTALP
CONV:
LEA SI,P11
MOV CL,L1
MOV CH,0
CHECK4:
CMP [SI],61H
JB DONE1
CMP [SI],5BH
UPR: SUB [SI],20H
DONE1: INC SI
LOOP CHECK4
DISPLAY MSG5
DISPLAY P11
JMP DONE
NOTALP:
DISPLAY MSG3
JMP DONE
NOT4D:
DISPLAY MSG4
DONE:
MOV AH,4CH
INT 21H
CODE ENDS
END START

Screen Shots :-

Asm_program_4digit_2_UpperCase

After Execution :-

Asm_program_4digit_2_UpperCase_Output

Note :- To see the variable and its value you have to click vars button in the emulator.