Sei sulla pagina 1di 64

/*2D array*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf("Enter the array elements");
for( i= 0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]) ;
}
}
printf("The elements of the array are");
for( i =0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
getch();
}

/*creation of lists*/
#include<stdio.h>
#include<conio.h>
#include<limits.h>
int select();
struct rec
{
float coef;
int exp;
struct rec *next;
};
struct rec *rear;
struct rec *create(struct rec *list);
void *add(struct rec *first,struct rec *second);
struct rec *insert(double coef,int exp,struct rec *rear);
void *display(struct rec *list);
int nodes;
void main()
{
struct rec *first=NULL,*second=NULL;
int choice;
do
{
choice=select();
switch(choice)
{
case 1: first=create(first);continue;
case 2: second=create(second);continue;
case 3: add(first,second);continue;
case 4: puts("END");exit(0);
}
}while(choice!=4);
}
int select()
{
int selection;
do
{
puts("Enter 1: create the first list");
puts("Enter 2: create the second list");
puts("Enter 3: add the two list");
puts("Enter 4: END");
puts("Entr your choice");
scanf("%d",&selection);
}while((selection<1)||(selection>4));
return (selection);
}
struct rec *create(struct rec *x)
{
float coef;
int exp;
int endexp=INT_MAX;
struct rec *element;
puts("Enter coefs &exp:exp in descending order:""to quit enter 0 for exp");
x=(struct rec *)malloc(sizeof(struct rec));

x->next=NULL;
rear=x;
for(;;)
{
puts("Enter coefficient");
element=(struct rec*)malloc(sizeof(struct rec));
scanf("%f",&coef);
element->coef=coef;
if(element->coef==0.0)break;
puts("Enter exponent");
scanf("%d",&exp);
element->exp=exp;
if((element->exp<=0)||(element->exp>=endexp))
{
puts("Invalid exponent");
break;
}
element->next=NULL;
rear->next=element;
rear=element;
}
x=x->next;
return(x);
}
void *add(struct rec *first,struct rec *second)
{
float total;
struct rec *end,*rear,*result;
result=(struct rec *)malloc(sizeof(struct rec));
rear=end;
while((first!=NULL)&&(second!=NULL))
{
if(first->exp==second->exp)
{
if((total=first->exp+second->exp)!=0.0)
rear=insert(total,first->exp,rear);
first=first->next;
second=second->next;
}
else
if(first->exp>second->exp)
{
rear=insert(first->coef,first->exp,rear);
first=first->next;
}else
{
rear=insert(second->coef,second->exp,rear);
second=second->next;
}
}
for(;first;first=first->next)
rear=insert(first->coef,first->exp,rear);
for(;second;second=second->next)
rear=insert(second->coef,second->exp,rear);
rear->next=NULL;
display(end->next);
free(end);

}
void *display(struct rec *head)
{
while(head!=NULL)
{
printf("%2lf",head->coef);
printf("%2d",head->exp);
head=head->next;
}
printf("\n");
}
struct rec *insert(double coef,int exp,struct rec *rear)
{
rear->next=(struct rec *)malloc(sizeof(struct rec));
rear=rear->next;
rear->coef=coef;
rear->exp=exp;
return(rear);
}

/*Deletion in the Array*/


#include<stdio.h>
#include<conio.h>
int i,n;
main()
{
int a[100],pos;
void delete(int a[],int,int);
clrscr();
printf("How many elements in the array\n");
scanf("%d",&n);
printf("Enter the element of the array\n");
for(i=0;i<=n-1;i++)
scanf("%d",&a[i]);
printf("On which postion element do you want delete\n");
scanf("%d",&pos);
delete(a,pos,n);
getch();
}
void delete(int a[],int pos,int n)
{
int j,item;
item=a[pos];
for(j=pos;j<=n-1;j++)
{
a[j]=a[j+1];
}
n=n-1;
for(i=0;i<=n-1;i++)
printf("%d\n",a[i]);
}

/*Factorial*/

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,result;
clrscr();
printf("Enter the number");
scanf("%d",&n);
result=fact(n);
printf("\n The factorial of %d is %d",n,result);
getch();
}
int fact(int x)
{
int f;
if(x==1)
{
return(x);
}
else
{
return(x*fact(x-1));
}
}

/*Fibonaci series*/
#include<stdio.h>
# include<conio.h>
void main()
{
int a[100],i,n;
clrscr();
printf("Enter the no. of elements in the series :\n ");
scanf("%d",&n);
a[0]=0;
a[1]=1;
for(i=2;i<=n-1;i++)
{
a[i] = a[i-2] + a[i-1];
}
printf("Fibonacci Series is : \n");
for(i=0;i<=n-1;i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*FIBONACCI SERIES*/
#include<stdio.h>
#include<conio.h>
void fseries(int);
void main()
{
int limit,f0=1,f1=1;
clrscr();
printf("Enter the limit of fibonacci series");
scanf("%d",&limit);
if(limit>2)
{
printf("%d\n%d",f0,f1);
fseries(limit-2);
}
else if(limit==2)
{
printf("\n %d \n %d",f0,f1);
}
else if(limit==1)
printf("%d",f1);
else
printf("Series not posible");
getch();
}
void fseries(int p)
{
int fib;
static int f0=1,f1=1;
if(p==0)
{
printf("\nThe series ends here");
}
else
{
fib=f0+f1;
f0=f1;
f1=fib;
printf("\n%d",fib);
fseries(p-1);
}
}

/*initialising the arrray*/


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i;
clrscr();
printf("Enter the array");
for(i = 0;i <=9;i ++)
{
scanf("%d",&a[i]);
}
printf("The entered array is");
for(i = 0;i <=9; i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*insert copy node*/

#include<stdio.h>
#include<conio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree,*second,*head;
struct rec *insert(struct rec *tree,long num);
struct rec *copy(struct rec *tree);
void inorder(struct rec *tree);
main()
{
int choice;
long digit;
do
{
choice=select();
switch(choice)
{
case 1:puts("Enter integers:To quit enter 0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: copy(tree);continue;
case 3: puts("Inorder traversing TREE");
inorder(tree);continue;
case 4: puts("END");exit(0);
}
}while(choice!=4);
}
int select()
{
int selection;
do
{
puts("Enter 1: Insert a node in the BST");
puts("Enter 2: Copy a tree to another BST");
puts("Enter 3: Display(inorder)the BST");
puts("Enter 4: END");
puts("Enter your choice");
scanf("%d",&selection);
if((selection<1)||(selection>4))
{puts("Wrong choice: Try again");
getchar();
}
}while((selection<1)||(selection>4));
return selection;
}

struct rec *insert(struct rec *tree,long digit)


{
if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec));
tree->left=tree->right=NULL;
tree->num=digit;
}
else
if(digit<tree->num)
tree->left=insert(tree->left,digit);
else if(digit>tree->num)
tree->right=insert(tree->right,digit);
else if(digit==tree->num)
{puts("Duplicate nodes: program exited");exit(0);
}
return(tree);
}
struct rec *copy(struct rec *tree)
{
second=(struct rec *)malloc(sizeof(struct rec));
head=second;
if(tree!=NULL)
{
second->num=tree->num;
if(tree->left!=NULL)
{
second->left->num=tree->left->num;
copy(tree->right);
}
if(tree->right!=NULL)
{
second->right->num=tree->num;
copy(tree->left);
}
}
return(head);
}
void inorder(struct rec *tree)
{
if(tree!=NULL)
{
inorder(tree->left);
printf("%12ld\n",tree->num);
inorder(tree->right);
}
}

/*insert node*/

#include<stdio.h>
#include<conio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree=NULL;
struct rec *insert(struct rec *tree,long num);
void depth(struct rec *tree);
struct rec *temp;
int count=1,total1,total2,dep;
void main()
{
struct rec *tree=NULL;
int choice;
long digit;
do
{
choice=select();
switch(choice)
{
case 1: puts("Enter integers: To quit enter0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: depth(tree);
if(total1>total2)
{
dep=total1-1;
printf("Depth=%d\n",dep);
}
else
dep=total2-1;
printf("Depth=%d\n",dep);
total1=total2=dep=0;
continue;
case 3: puts("END");exit(0);
}
}while(choice!=3);
}
int select()
{
int selection;
do
{
puts("Enter 1: Insert a node");
puts("Enter 2: Display depth");
puts("Enter 3: END");

puts("Eter your choice");


scanf("%d",&selection);
if((selection<1)||(selection>3))
{
puts("Wrong choice: Try again");
getchar();
}
}while((selection<1)||(selection>3));
return selection;
}
struct rec *insert(struct rec *tree,long digit)
{
if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec));
tree->left=tree->right=NULL;
tree->num=digit;
}
else
if(count%2==0)
tree->left=insert(tree->left,digit);
else
tree->right=insert(tree->right,digit);
return(tree);
}
void depth(struct rec *tree)
{
if(tree!=NULL)
{
if(tree->left!=NULL)
{
total1++;
depth(tree->left);
}
if(tree->right!=NULL)
{
total2++;
depth(tree->right);
}
}
}

/*insert subtree*/

#include<stdio.h>
#include<conio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree=NULL;
struct rec *insert(struct rec *tree,long num);
void *exchange(struct rec *tree);
struct rec *temp;
void main()
{
struct rec *tree=NULL;
int choice;
long digit;
do
{
choice=select();
switch(choice)
{
case 1: puts("Enter integer: To quit enter 0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: printf("%5d\n",tree->num);exchange(tree);continue;
case 3: puts("END");exit(0);
}
}while(choice!=3);
}
int select()
{
int selection;
do
{
puts("Enter 1: Insert a node");
puts("Enter 2: Exchange subtrees");
puts("Enter 3: End");
puts("Enter your choice");
scanf("%d",&selection);
if((selection<1)||(selection>3))
{puts("Wrong choice: Try again");
getchar();
}
}while((selection<1)||(selection>3));
return selection;
}
struct rec *insert(struct rec *tree,long digit)
{

if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec));
tree->left=tree->right=NULL;
tree->num=digit;
}
else
if(digit<tree->num)
tree->left=insert(tree->left,digit);
else if(digit>tree->num)
tree->right=insert(tree->right,digit);
else if(digit==tree->num)
{puts("Duplicates Nodes: Program Exited");exit(0);
}
return(tree);
}
void *exchange(struct rec *tree)
{
if((tree->left->num!=0)&&(tree->right->num!=0))
{
temp=tree->left;
tree->left=tree->right;
tree->right=temp;
printf("%5ld\n",tree->left->num);
printf("%5ld\n",tree->right->num);
exchange(tree->left);
exchange(tree->right);
}
}

/*insertion and deletion at places*/

#include<stdio.h>
#include<conio.h>
struct node
{
int info;
struct node *left,*right;
};
typedef struct node NODE;
NODE *head;
insert_cir(NODE *head)
{
NODE *ptr,*temp;
int item;
ptr=(NODE *)malloc(sizeof(NODE));
printf("Enter the no\n");
scanf("%d",&item);
ptr->info=item;
temp=head->right;
head->right=ptr;
ptr->left=head;
ptr->right=temp;
temp->left=ptr;
return (head);
}
insert_cir_end(NODE *head)
{
NODE *ptr,*temp;
int item;
ptr=(NODE *)malloc(sizeof(NODE));
printf("Enter the no\n");
scanf("%d",&item);
ptr->info=item;
temp=head->left;
temp=head->left;
temp->right=ptr;
ptr->left=temp;
ptr->right=head;
head->left=ptr;
return (head);
}
dele_beg(NODE *head)
{
NODE *temp;
if(head->right==head)
{
printf("Empty list\n");
return;
}
else
{
temp=head->right;
printf("deleted element is =%d\n",temp->info);
head->right=temp->right;

temp->right->left=head;
free(temp);
return (head);
}
}
dele_end(NODE *head)
{
NODE *temp;
if(head->right==head)
{
printf("empty list\n");
return;
}
else
{
temp=head->left;
printf("deleted elementis =%d\n",temp->info);
head->left=temp->left;
free(temp);
return (head);
}
}
void main()
{
int left,right,choice;
clrscr();
do
{
printf("Enter 1: insert at the begining of the
printf("Enter 2: insert at the end of the link
printf("Enter 3: delete at the begining of the
printf("Enter 4: delete at the end of the link
printf("Enter 5: end\n");
printf("Enter your choice\n" );
scanf("%d",&choice);
switch(choice)
{
case 1: insert_cir(head);
break;
case 2: insert_cir_end(head);
break;
case 3: dele_beg(head);
break;
case 4: dele_end(head);
break;
case 5: return;
}
}while(choice!=5);
getch();
}

link list\n");
list\n");
link list\n");
list\n");

/*Insertion and Deletion*/


#include<stdio.h>
#include<conio.h>
struct stack
{
int no;
struct stack *next;
}
*start=NULL;
typedef struct stack st;
void push();
int pop();
void display();
void main()
{
char ch;
int choice,item;
do
{
clrscr();
printf("\n 1: push");
printf("\n 2: pop");
printf("\n 3: display");
printf("\n Enter your choice");
scanf("%d",&choice);
switch (choice)
{
case 1: push();
break;
case 2: item=pop();
printf("The delete element in %d",item);
break;
case 3: display();
break;
default : printf("\n Wrong choice");
};
printf("\n do you want to continue(Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while (ch=='Y'||ch=='y');
}
void push()
{
st *node;
node=(st *)malloc(sizeof(st));
printf("\n Enter the number to be insert");
scanf("%d",&node->no);
node->next=start;
start=node;
}
int pop()
{
st *temp;
temp=start;

if(start==NULL)
{
printf("stack is already empty");
getch();
exit();
}
else
{
start=start->next;
free(temp);
}
return(temp->no);
}
void display()
{
st *temp;
temp=start;
while(temp->next!=NULL)
{
printf("\nno=%d",temp->no);
temp=temp->next;
}
printf("\nno=%d",temp->no);
}

/*Insertion in array*/
#include<stdio.h>
#include<conio.h>
int i,len,pos,num;
void main()
{
int a[100];
void insert(int a[], int, int, int);
clrscr();
printf("Enter integers to be read");
scanf("%d",&len);
printf("Enter integers");
for(i=0;i<=len;i++)
{
scanf("%d",&a[i]);
}
printf("Enter integer to be inserted");
scanf("%d",&num);
printf("Enter position in the array for insertion");
scanf("%d",&pos);
--pos;
insert(a,len,pos,num);
}
void insert (int a[], int len, int pos, int num)
{
for(i=len;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=num;
if(pos>len)
{
printf("insertion outside the array");
}
len++;
printf("New array");
for(i=0;i<len;i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*Insertion in array*/
#include<stdio.h>
#include<conio.h>
int i,len,pos,num;
void main()
{
int a[100];
void insert(int a[], int, int, int);
clrscr();
printf("Enter integers to be read");
scanf("%d",&len);
printf("Enter integers");
for(i=0;i<=len;i++)
{
scanf("%d",&a[i]);
}
printf("Enter integer to be inserted");
scanf("%d",&num);
printf("Enter position in the array for insertion");
scanf("%d",&pos);
--pos;
insert(a,len,pos,num);
}
void insert (int a[], int len, int pos, int num)
{
for(i=len;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=num;
if(pos>len)
{
printf("insertion outside the array");
}
len++;
printf("New array");
for(i=0;i<len;i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*linked list*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void main()
{
struct node
{
int num;
struct node *ptr;
};
typedef struct node NODE;
NODE *head, *first, *temp;
int count=0;
int choice=1;
first=NULL;
while(choice)
{
head=(NODE *)malloc(sizeof(NODE));
printf("Enter the data item\n");
scanf("%d",&head->num);
if(first!=NULL)
{
temp->ptr=head;
temp=head;
}
else
{
first=temp=head;
}
fflush(stdin);
printf("Do you want to continue(type 0 or 1)?\n");
scanf("%d",&choice);
}
temp->ptr=NULL;
temp=first;
printf("Status of the linked list is\n");
while(temp!=NULL)
{
printf("%d",temp->num);
count++;
temp=temp->ptr;
}
printf("NULL");
printf("NO of nodes in the list =%d\n",count);
getch();
}

/*insertion in tree*/

#include<stdio.h>
#include<conio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree=NULL;
struct rec *insert(struct rec *tree,long num);
void countnode(struct rec *tree);
void countleave(struct rec *tree);
struct rec *temp;
int node=1,total;
main()
{
struct rec *tree=NULL;
int choice;
long digit;
do
{
choice=select();
switch(choice)
{
case 1: puts("Enter integers:To quit enter 0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: countnode(tree);
printf("Nuber of nodes=%d\n",node);
node=1;continue;
case 3: countleave(tree);
printf("Nuber of leaves=%d\n",total);
total=0;
continue;
case 4: puts("END");exit(0);
}
}while(choice!=4);
}
int select()
{
int selection;
do
{
puts("Enter 1: Insert a node");
puts("Enter 2: Display number of nodes");
puts("Enter 3: Display number of leave");
puts("Enter 4: End");
puts("Enter your choice");
scanf("%d",&selection);

if((selection<1)||(selection>4))
{
puts("Wrong choice: Try again");
getchar();
}
}while((selection<1)||(selection>4));
return selection;

}
struct rec *insert(struct rec *tree,long digit)
{
if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec ));
tree->left=tree->right=NULL;
tree->num=digit;
}
else
if(digit<tree->num)
tree->left=insert(tree->left,digit);
else
if(digit>tree->num)
tree->right=insert(tree->right,digit);
else
if(digit==tree->num)
{
puts("Duplicates Nodes:Program Exited");
exit(0);
}
return(tree);
}
void countnode(struct rec *tree)
{
if(tree!=NULL)
{
if(tree->left!=NULL)
{
node++;
countnode(tree->left);
}
if(tree->right!=NULL)
{
node++;
countnode(tree->right);
}
}
}
void countleave(struct rec *tree)
{
if(tree!=NULL)
{
if((tree->left==NULL)&&(tree->right==NULL))
total++;
else
countleave(tree->left);
countleave(tree->right);
}
}

/*insertion in linked list*/


#include<stdio.h>
#include<conio.h>
int select();
struct rec
{
char name[80];
struct rec *next;
};
struct rec *rear;
struct rec *create(struct rec *list);
struct rec *insert1(struct rec *node);
struct rec *insert2(struct rec *node);
struct rec *insert3(struct rec *node);
struct rec *insert4(struct rec *node);
struct rec *delete(struct rec *node);
void *display(struct rec *list);
int nodes;
main()
{
struct rec *first=NULL;
int choice;
clrscr();
do
{
choice=select();
switch(choice)
{
case 1: first=create(first);continue;
case 2: first=insert1(first);continue;
case 3: first=insert2(first);continue;
case 4: first=insert3(first);continue;
case 5: first=insert4(first);continue;
case 6: first=delete(first);continue;
case 7: display(first);continue;
case 8: puts("END");exit(0);
}
}while(choice!=8);
}
int select()
{
int selection;
do
{
puts("Enter 1: create the list");
puts("Enter 2: insert in the beginnig of the list");
puts("Enter 3: insert after a node in the list");
puts("Enter 4: insert before a node in the list");
puts("Enter 5: insert in the end of the list");
puts("Enter 6: delete the list");
puts("Enter 7: display the list");
puts("Enter 8: END");
puts("Enter your choice");
scanf("%d",&selection);
}while(selection<1||selection>8);

return selection;
}
struct rec *create(struct rec *first)
{
struct rec *element;
first=(struct rec*)malloc(sizeof(struct rec));
puts("Enter/name/word/text: To quit enter*");
scanf(" %[^\n]",first->name);
first->next=first;
rear=first;
rear->next=first;for(;;)
{
element=(struct rec*)malloc(sizeof(struct rec));
scanf(" %[^\n]",element->name);
if(strcmp(element->name,"*")==0)break;
element->next=first;
rear->next=element;
rear= element;
}
return(first);
}
struct rec *insert1(struct rec *first)
{
struct rec *node;
node=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name to be inserted");
scanf(" %[^\n]",node->name);
if(first==NULL)
{
node->next=first;
rear=first;
}
else
{
node->next=first;
first=node;
rear->next=first;
}
return(first);
}
struct rec *insert2(struct rec *first)
{
struct rec *current,*prior,*x;
struct rec *node;current=first;
node=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name after which new node to be inserted");
scanf(" %[^\n]\n",node->name);
x=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name to be inserted");
scanf(" %[^\n]",x->name);
while(current!=rear && current!=NULL)
{
if(strcmp(current->name,node->name)==0)
{
x->next=current->next;
current->next=x;

return(first);
}
else current=current->next;
}
if(strcmp(current->name,node->name)==0)
{
x->next=first;
rear->next=x;
rear=x;
return(first);
}
puts("Node does not exist in the list");
return(first);
}
struct rec *insert3(struct rec *first)
{
struct rec *node,*current,*x,*prior;
current=first;
node=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name before which new node to be inserted");
scanf(" %[^\n]",node->name);
x=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name to be inserted");
scanf(" %[^\n]",x->name);
if(strcmp(current->name,node->name)==0)
{
x->next=first;
first=x;
return(first);
}
while(current!=NULL)
{
prior=current;
current=current->next;
if(strcmp(current->name,node->name)==0)
{
x->next=current;
prior->next=x;
return(first);
}
}
puts("Node does not exist in the list");
return(first);
}
struct rec *insert4(struct rec *first)
{
struct rec *element;
element=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name to be inserted at the end of list");
scanf(" %[^\n]",element->name);
element->next=first;
rear->next=element;
rear=element;
return(first);
}
struct rec *delete(struct rec *first)
{

struct rec *current,*prior,*node;


current=first;
node=(struct rec*)malloc(sizeof(struct rec));
puts("Enter node/name to be delete");
scanf(" %[^\n]",node->name);
if(strcmp(current->name,node->name)==0)
{
first=current->next;
rear->next=first;
free(current);
return(first);
}
while(current!=rear && current!=NULL)
{
prior=current;
current=current->next;
if(strcmp(current->name,node->name)==0)
{
prior->next=current->next;
free(current);
return(first);
}
}
if(strcmp(current->name,node->name)==0)
{
prior->next=current->next;
prior->next=first;
rear=prior;
free(current);
return(first);
}
puts("Node does not exist in the list");
return(first);
}
void *display(struct rec *first)
{
int node=0;
do
{
node++;
printf("%s\n",first->name);
first=first->next;
}
while((first!=rear->next)&&(first!=NULL));
printf("Nuber of nodes= %d\n",node);
}

/*Multiplication of the Matrix*/


#include<stdio.h>
#include<conio.h>
void main( )
{
int a[2][2], b[2][2],s[2][2];
int i,j,k;
clrscr();
printf("Enter first matrix:\n" );
for( i=1;i<=2;i++)
{
for( j=1;j<=2;j++)
{
printf("Enter%d%d\n",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter second matrix:\n");
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
printf("Enter %d%d\n",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=2;i++)
{

for(j=1;j<=2;j++)
{
s[i][j]=0;
for(k=1;k<=2;k++)
{
s[i][j] =s[i][j]+a[i][k]*b[k][j];
}
}

printf("Matrix Multiplication Is: \n");


for(i=1;i<=2;i++)
{
for (j=1;j<=2;j++)
{
printf("%d\n",s[i][j]);
}
}
getch();
}

/*various operation on linked lists*/

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct node
{
int info;
struct node *next;
};
typedef struct node NODE;
NODE *start;
void createmptylist(NODE **start)
{
*start=(NODE *)NULL;
}
void traversinorder(NODE *start)
{
while(start != (NODE *) NULL)
{
printf("%d\n",start->info);
start=start->next;
}
}
void insertatbegin(int item)
{
NODE *ptr;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->info=item;
if(start==(NODE *)NULL)
ptr->next=(NODE *)NULL;
else
ptr->next=start;
start=ptr;
}
void insert_at_end(int item)
{
NODE *ptr,*loc;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->info=item;
ptr->next=(NODE *)NULL;
if(start==(NODE*)NULL)
start=ptr;
else
{
loc=start;
while(loc->next!=(NODE *)NULL)
loc=loc->next;
loc->next=ptr;
}
}
void dele_beg(void)
{
NODE *ptr;

if(start==(NODE *)NULL)
return;
else
{
ptr=start;
start=(start)->next;
free(ptr);
}
}
void dele_end(NODE *start)
{
NODE *ptr,*loc;
if(start==(NODE *)NULL)
return;
else if((start)->next==(NODE *)NULL)
{
ptr=start;
start=(NODE *)NULL;
free(ptr);
}
else
{
loc=start;
ptr=(start)->next;
while(ptr->next!=(NODE *)NULL)
{
loc=ptr;
ptr=ptr->next;
}
loc->next=(NODE *)NULL;
free(ptr);
}
}
void insert_spe(NODE *start,int item)
{
NODE *ptr,*loc;
int temp,k;
for(k=0,loc=start;k<temp;k++)
{
loc=loc->next;
if(loc==NULL)
{
printf("node in the list at less than one\n");
return;
}
}
ptr=(NODE *)malloc(sizeof(NODE));
ptr->info=item;
ptr->next=loc->next;;
loc->next=ptr;
}
dele_spe(NODE *start)
{
NODE *ptr,*loc;
int temp;
printf("\nEnter the which element do you want to delete\n");
scanf("%d",&temp);

ptr=start;
if(start==NULL)
{
printf("Empty list\n");
return;
}
else
{
loc=ptr;
while(ptr!=NULL)
{
if(ptr->info==temp)
{
loc->next=ptr->next;
free(ptr);
return;
}
loc=ptr;
ptr=ptr->next;
}
}
}
void main()
{
int choice,item,after;
char ch;
clrscr();
createmptylist(start);
do
{
printf("1.Insert element at begin \n");
printf("2. insert element at end positon\n");
printf("3. insert specific the position\n");
printf("4.travers the list in order\n");
printf("5. delete from the begin\n");
printf("6. delete from the last\n");
printf("7. delete the element from the specific position\n");
printf("8. exit\n");
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the item\n");
scanf("%d",&item);
insertatbegin(item);
break;
case 2: printf("Enter the item\n");
scanf("%d",&item);
insert_at_end(item);
break;
case 3: printf("Enter the item\n");
scanf("%d",&item);
insert_spe(start,item);
break;
case 4: printf("\ntravers the list\n");
traversinorder(start);
break;

case 5: printf("Delete the item\n");


dele_beg();
break;
case 6: printf("Delete the element\n");
dele_end(start);
break;
case 7: printf("Delete the element");
dele_spe(start);
break;
case 8: return;
}
fflush(stdin);
printf("do your want continous\n");
scanf("%c",&ch);
}while((ch='y')||(ch='y'));
getch();
}

/*queue*/
#include<stdio.h>
#include<conio.h>
#define MAXSIZE 5
int cq[10];
int front=-1,rear=0;
int choice;
char ch;
void main()
{
clrscr();
do
{
printf("--------1.Insert-------\n");
printf("------- 2. Delete--------\n");
printf("------- 3. Display--------\n");
printf("-------4.exit------------\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1 : cqinsert();
break;
case 2 : cqdelete();
break;
case 3 : cqdisplay();
break;
case 4: return;
}
fflush(stdin);
}
while(choice!=4);
}
cqinsert()
{
int num;
if(front==(rear+1)%MAXSIZE)
{
printf("Queue is full\n");
return;
}
else
{
printf("Enter the element to be inserted\n");
scanf("%d",&num);
if(front==-1)
front=rear=0;
else
rear=(rear+1) % MAXSIZE;
cq[rear]= num;
}

return;
}
int cqdelete()
{
int num;
if(front==-1)
{
.
printf("Queue is Empty\n");
return;
}
else
{
num=cq[front];
printf("Deleted element is =%d\n",cq[front]);
if(front==rear)
front=rear=-1;
else
front=(front+1)%MAXSIZE;
}
return(num);
}
cqdisplay()
{
int i;
if(front==-1)
{
printf("Queue is empty\n");
return;
}
else
{
printf("\nThe status of the queue\n");
for(i=front;i<=rear;i++)
{
printf("%d\n",cq[i]);
}
}
if(front>rear)
{
for(i=front;i<MAXSIZE;i++)
{
printf("%d\n",cq[i]);
}
for(i=0;i<=rear;i++)
{
printf("%d\n",cq[i]);
}
}
printf("\n");
}

/*Numeric Palindrome*/
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a[10], num, i=0, result=0, n;
clrscr();
printf("enter the number");
scanf("%d",&n);
num = n;
while (num!=0)
{
result=result*10;
a[i]=num%10;
num=num/10;
result=result+a[i];
i++;
}
if (result == n)
printf("The number is pallandrome");
getch( );
}

/*Prime number*/
#include<stdio.h>
#include<conio.h>
int prime(int);
void main()
{
int n,f=0;
clrscr();
printf("\nEnter the number");
scanf("%d",&n);
if(n==2)
{
printf("The number is prime");
}
else if(n<2)
{
printf("The smallest prime number is 2");
}
else
{
f=prime(n);
if(f)
{
printf("Number is prime");
}
else
printf("Not prime");
}
getch();
}
int prime(int a)
{
static int d=2,flag=1;
if(d==a)
{
return(0);
}
else
{
if(a%d==0)
{
flag=0;
d++;
}
else
{
d++;
flag=1;
prime(a);
}
}
return(flag);
}

/*queue operations*/
#include<stdio.h>
#include<conio.h>
struct queue
{
int no;
struct queue *next;
}
*start=NULL;
void add();
int del();
void traverse();
void main()
{
int ch;
char choice;
do
{
clrscr();
printf("----1. add\n");
printf("----2. delete\n");
printf("----3. traverse\n");
printf("----4. exit\n");
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
break;
case 2: printf("the delete element is\n%d",del());
break;
case 3: traverse();
break;
case 4: return;
default : printf("wrong choice\n");
};
fflush(stdin);
scanf("%c",&choice);
}
while(choice!=4);
}
void add()
{
struct queue *p,*temp;
temp=start;
p=(struct queue*)malloc(sizeof(struct queue));
printf("Enter the data");
scanf("%d",&p->no);
p->next=NULL;
if(start==NULL)
{
start=p;
}

else
{
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=p;
}
}
int del()
{
struct queue *temp;
int value;
if(start==NULL)
{
printf("queue is empty");
getch();
return(0);
}
else
{
temp=start;
value=temp->no;
start=start->next;
free(temp);
}
return(value);
}
void traverse()
{
struct queue *temp;
temp=start;
while(temp->next!=NULL)
{
printf("no=%d",temp->no);
temp=temp->next;
}
printf("no=%d",temp->no);
getch();
}

/*queue various operation*/


#include<stdio.h>
#include<conio.h>
#define MAXSIZE 5
int front=-1, rear=-1,choice;
int q[10];
void main()
{
clrscr();
do
{
printf("\n1-->insert\n");
printf("2-->delete\n");
printf("3-->display\n");
printf("4-->exit\n");
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:qinsert();
break;
case 2:qdelete();
break;
case 3:qdisplay();
break;
case 4:return;
}
}
while(choice!=4);
}
qinsert()
{
int num;
if(rear==(MAXSIZE-1))
{
printf("queue is full\n");
return;
}
else
{
printf("enter no\n");
scanf("%d",&num);
rear=rear+1;
q[rear]=num;
if(front==-1)
{
front++;
}
}
return;
}
qdelete()
{
int num;
if(front==-1)

{
printf("queue empty\n");
return;
}
else
{
if(front==rear)
front=rear=-1;
else
{
num=q[front];
printf("deleted item=%d",q[front]);
front++;
}
}
return(num);
}
qdisplay()
{
int i;
if(front==-1)
{
printf("queue empty\n");
return;
}
else
{
printf("\nThe status of the queu\n");
for(i=front;i<=rear;i++)
{
printf("%d\n",q[i]);
}
}
printf("\n");
}

/*search*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,loc,mid,beg,end,n,flag=0,item;
clrscr();
printf("How many elements");
scanf("%d",&n);
printf("Enter the element of the array\n");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be searching\n");
scanf("%d",&item);
loc=0;
beg=0;
end=n-1;
while((beg<=end)&&(item!=a[mid]))
{
mid=((beg+end)/2);
if(item==a[mid])
{
printf("search is successfull\n");
loc=mid;
printf("position of the item%d\n",loc+1);
flag=flag+1;
}
if(item<a[mid])
end=mid-1;
else
beg=mid+1;
}
if(flag==0)
{
printf("search is not successfull\n");
}
getch();
}

/*searching of tree*/

#include<stdio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree=NULL;
struct rec *tree;
struct rec *delnum(long digit,struct rec *r);
struct rec *insert(struct rec *tree,long num);
struct rec *deletenode(long digit,struct rec *tree);
void search(struct rec *tree,long num);
void preorder(struct rec *tree);
void inorder(struct rec *tree);
void postorder(struct rec *tree);
void main()
{
int choice;
long digit;
int element;
do
{
choice=select();
switch(choice)
{
case 1: puts("Enter integer: To quit enter 0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: puts("Enter the number to be search");
scanf("%ld",&digit);
search(tree,digit);
continue;
case 3: puts("\npreorder traversing TREE");
preorder(tree);continue;
case 4: puts("\ninorder traversing TREEE");
inorder(tree);continue;
case 5: puts("\npostorder traversing TREE");
postorder(tree);continue;
case 6: puts("Enter element which do you wanbt delete from
BST");
scanf("%ld",&digit);
deletenode(digit,tree);continue;
case 7: puts("END");exit(0);
}
}while(choice!=7);
}
int select()
{

the

int selection;
do
{
puts("Enter 1: Insert a node in the BST");
puts("Enter 2: Search a node in BST");
puts("Enter 3: Display(preorder)the BST");
puts("Enter 4: Display(inorder)the BST");
puts("Enter 5: Display(postorder) the BST");
puts("Enter 6: Delete the element");
puts("Enter 7: END");
puts("Enter your choice");
scanf("%d",&selection);
if((selection<1)||(selection>7))
{
puts("wrong choice:Try again");
getch(); }
}while((selection<1)||(selection>7));
return (selection);
}
struct rec *insert(struct rec *tree,long digit)
{
if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec));
tree->left=tree->right=NULL;
tree->num=digit;
}
else
if(digit<tree->num)
tree->left=insert(tree->left,digit);
else
if(digit>tree->num)
tree->right=insert(tree->right,digit);
else if(digit==tree->num)
{
puts("Duplicate node:program exited");exit(0);
}
return(tree);
}
struct rec *delnum(long digit,struct rec *r)
{
struct rec *q;
if(r->right!=NULL)delnum(digit,r->right);
else
q->num=r->num;
q=r;
r=r->left;
}
struct rec *deletenode(long digit,struct rec *tree)
{
struct rec *r,*q;
if(tree==NULL)
{
puts("Tree is empty.");
exit(0);
}
if(digit<tree->num)

deletenode(digit,tree->left);
else
if(digit>tree->num)deletenode(digit,tree->right);
q=tree;
if((q->right==NULL)&&(q->left==NULL))
q=NULL;
else
if(q->right==NULL)tree=q->left;else
if(q->left==NULL)tree=tree=q->right;else
delnum(digit,q->left);
free(q);
}
void search(struct rec *tree,long digit)
{
if(tree==NULL)
puts("The number does not exits\n");
else
if(digit==tree->num)
printf("Number=%ld\n" ,digit);
else
if(digit<tree->num)
search(tree->left,digit);
else
search(tree->right,digit);

}
void preorder(struct rec *tree)
{
if(tree!=NULL)
{
printf("%12ld\n",tree->num);
preorder(tree->left);
preorder(tree->right);
}
}
void inorder(struct rec *tree)
{
if(tree!=NULL)
{
inorder(tree->left);
printf("%12ld\n",tree->num);
inorder(tree->right);
}
}
void postorder(struct rec *tree)
{
if(tree!=NULL)
{
postorder(tree->left);
postorder(tree->right);
printf("%12ld\n",tree->num);
}
}

/**Selection sorting/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,j,temp,loc,min;
clrscr();
printf("\How many elements:\n");
scanf("%d",&n);
printf("Enter the element of array\n");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
min=a[0];
for(i=0;i<=n-1;i++)
{
min=a[i];
loc=i;
for(j=i+1;j<=n-1;j++)
{
if(a[j]<min)
{
min=a[j];
loc=j;
}
}
if(loc!=1)
{
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
}
printf("The number after selection sorting are:\n");
for(i=0;i<=n-1;i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*sorting of 2D arrays*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,j,temp;
clrscr();
printf("How many elements");
scanf("%d",&n);
printf("Enter the element of array");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Element of array after the sorting are:\n");
for(i=0;i<=n-1;i++)
{
printf("%d\n",a[i]);
}
getch();
}

/*Sorting of array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int p,q,m,n,c;
int array1[100],array2[100],array3[200];
clrscr();
puts("Enter number of element of the first sorted array");
scanf("%d",&p);
puts("Enter element of the first sorted array");
for(m=0;m<=p;m++)
scanf("%d",&array1[m]);
puts("Enter number of element of the second sorted array");
scanf("%d",&q);
puts("Enter element of the second array");
for(n=0;n<=q;n++)
scanf("%d",&array2[n]);
c=0;
m=0;
n=0;
while((m<q)&&(n<q))
{
if(array1[m]<=array2[n])
array3[c]=array1[m++];
else
array3[c]=array2[n++];
c++;
}
while(m<p)
{
array3[c]=array1[m];
c++;
m++;
}
while(n<q)
{
array3[c]=array2[n];
c++;
n++;
}
puts("merged array in ascending order");
for(m=0;m<=c;m++)
printf("%d",array3[m]);
getch();
}

/*stack operations*/
#include<stdio.h>
#include<conio.h>
struct stack
{
int no;
struct stack *next;
}
*start=NULL;
typedef struct stack st;
void push();
int pop();
void display();
void main()
{
char ch;
int choice,item;
do
{
clrscr();
printf("\n 1: push");
printf("\n 2: pop");
printf("\n 3: display");
printf("\n Enter your choice");
scanf("%d",&choice);
switch (choice)
{
case 1: push();
break;
case 2: item=pop();
printf("The delete element in %d",item);
break;
case 3: display();
break;
default : printf("\n Wrong choice");
};
printf("\n do you want to continue(Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while (ch=='Y'||ch=='y');
}
void push()
{
st *node;
node=(st *)malloc(sizeof(st));
printf("\n Enter the number to be insert");
scanf("%d",&node->no);
node->next=start;
start=node;
}
int pop()
{
st *temp;
temp=start;

if(start==NULL)
{
printf("stack is already empty");
getch();
exit();
}
else
{
start=start->next;
free(temp);
}
return(temp->no);
}
void display()
{
st *temp;
temp=start;
while(temp->next!=NULL)
{
printf("\nno=%d",temp->no);
temp=temp->next;
}
printf("\nno=%d",temp->no);
}

/*Stack various operations*/


#include<stdio.h>
#include<conio.h>
#define MAXSIZE 10
void push();
int pop();
void traverse();
int stack[MAXSIZE];
int Top=-1;
void main()
{
int choice;
char ch;
do
{
clrscr();
printf("\n1. PUSH ");
printf("\n2. POP ");
printf("\n3. TRAVERSE ");
printf("\nEnter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: printf("\nThe deleted element is %d",pop());
break;
case 3: traverse();
break;
default: printf("\nYou Entered Wrong Choice");
}
printf("\nDo You Wish To Continue (Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while(ch=='Y' || ch=='y');
}
void push()
{
int item;
if(Top == MAXSIZE - 1)
{
printf("\nThe Stack Is Full");
getch();
exit(0);
}
else
{
printf("Enter the element to be inserted");
scanf("%d",&item);
Top= Top+1;
stack[Top] = item;
}
}

int pop()
{
int item;
if(Top == -1)
{
printf("The stack is Empty");
getch();
exit(0);
}
else
{
item = stack[Top];
Top = Top-1;
}
return(item);
}
void traverse()
{
int i;
if(Top == -1)
{
printf("The Stack is Empty");
getch();
exit(0);
}
else
{
for(i=Top;i>=0;i--)
{
printf("Traverse the element");
printf("\n%d",stack[i]);
}
}
}

/*sum of elements of array*/


#include<stdio.h>
#include<conio.h>
int funarray(int [], int);
void main()
{
int a[10],i,sum=0;
clrscr();
printf("Enter the array");
for(i =0;i<=9;i++)
{
scanf("%d",&a[i]);
}
sum=funarray(a,9);
printf("The sum of array elements is%d",sum);
getch();
}
int funarray(int p[], int n)
{
int i,s=0;
for(i=0;i<=n;i++)
{
s=s+p[i];
}
return(s);
}

/*Symmetric Matrix*/
#include<stdio.h>
# include<conio.h>
void main()
{
int a[10][10],n,i,j,flag;
clrscr();
printf("Enter order of the matrix : ");
scanf("%d",&n);
printf( "Enter the elements : \n");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1;j++)
{
scanf("%d",a[i][j]);
}
}
flag = 1;
for(i=0;i<=n-1;i++)
{
for(j=i+1;j<=n-1;j++)
{
if((a[i][j] - a[i][j]) != 0)
flag =0;
break;
}
}
if(flag)
printf("Symmetric matrix ");
else
printf("Not a symmetric matrix");
getch();
}

/*Transpose of the matrix*/


#include<stdio.h>
# include<conio.h>
void main()
{
int a[10][10],b[10][10],i,j,m,n;
clrscr();
printf("Enter the order of the matrix\n");
printf("No. of rows : \n");
scanf("%d",&n);
printf("No. of columns :\n ");
scanf("%d",&m);
printf("Enter the matrix elements\n");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
scanf("%d\n",&a[i][j]);
b[j][i] = a[i][j];
}
}
printf("Matrix A was\n ");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
printf("%d\n",a[i][j]);
}
}
printf("Transpose of matrix A is \n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\n",b[i][j]);
}
}
getch( );
}

/*traversing of tree*/
#include<stdio.h>
struct rec
{
long num;
struct rec *left;
struct rec *right;
};
struct rec *tree=NULL;
struct rec *insert(struct rec *tree,long num);
void preorder(struct rec *tree);
void inorder(struct rec *tree);
void postorder(struct rec *tree);
int count=1;
main()
{
int choice;
long digit;
do
{
choice=select();
switch(choice)
{
case 1: puts("Enter integer: To quit enter 0");
scanf("%ld",&digit);
while(digit!=0)
{
tree=insert(tree,digit);
scanf("%ld",&digit);
}continue;
case 2: puts("\npreorder traversing TREE");
preorder(tree);continue;
case 3: puts("\ninorder traversing TREEE");
inorder(tree);continue;
case 4: puts("\npostorder traversing TREE");
postorder(tree);continue;
case 5: puts("END");exit(0);
}
}while(choice!=5);
}
int select()
{
int selection;
do
{
puts("Enter 1: Insert a node in the BT");
puts("Enter 2: Display(preorder)the BT");
puts("Enter 3: Display(inorder)the BT");
puts("Enter 4: Display(postorder)the BT");
puts("Enter 5: END");
puts("Enter your choice");
scanf("%d",&selection);
if((selection<1)||(selection>5))
{
puts("wrong choice:Try again");
getch(); }
}while((selection<1)||(selection>5));

return (selection);
}
struct rec *insert(struct rec *tree,long digit)
{
if(tree==NULL)
{
tree=(struct rec *)malloc(sizeof(struct rec));
tree->left=tree->right=NULL;
tree->num=digit;count++;
}
else
if(count%2==0)
tree->left=insert(tree->left,digit);
else
tree->right=insert(tree->right,digit);
return(tree);
}
void preorder(struct rec *tree)
{
if(tree!=NULL)
{
printf("%12ld\n",tree->num);
preorder(tree->left);
preorder(tree->right);
}
}
void inorder(struct rec *tree)
{
if(tree!=NULL)
{
inorder(tree->left);
printf("%12ld\n",tree->num);
inorder(tree->right);
}
}
void postorder(struct rec *tree)
{
if(tree!=NULL)
{
postorder(tree->left);
postorder(tree->right);
printf("%12ld\n",tree->num);
}
}

/*Triangular Matrix*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,n,flag;
clrscr();
printf("Enter the order of the matrix : ");
scanf("%d",&n);
printf("Enter matrix elements :\n ");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("i=%dj=%d\n",i,j);
scanf("%d",&a[i][j]);
}
}
flag = 1;
for(i=0;i<=n-2;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i][j] !=0) flag = 0;
break;
}
}
if(flag)
printf("Upper triangle matrix ");
else
printf("Not a Upper triangle matrix");
getch();
}

/*Various_array_operations*/
#include<stdio.h>
#include<conio.h>
void insert();
void del();
void traversa();
void merged();
int a[10],i=-1;
void main()
{
int n;
do
{
printf("***************************** YOUR CHOICES ARE
****************************\n");
printf("1. Insert\n");
printf("2. Delete\n");
printf("3. Traverse\n");
printf("4. Merged\n");
printf("5. Exit\n");
printf("NOW ENTER YOUR CHOICE : \n");
scanf("%d",&n);
switch(n)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
traversa();
break;
case 4: merged();
break;
case 5:
break;
default:
printf("YOUR CHOICE IS INVALID");
}
}while(n!=5);
getch();
}
void insert()
//Body of insert function
{
if(i<=8)
{
printf("Enter the No.\n");
while(i<=8)
{
i++;
scanf("%d",&a[i]);
}

}
else
{
}

printf("The Array is Full");

void del()
//Body of del function
{
int item,j,flag=0,pos;
printf("Enter the no to delete : ");
scanf("%d",&item);
for(j=0;j<=i;j++)
{
if(a[j]==item)
{
flag=1;
pos=j;
}
}
if(flag)
{
for(j=pos;j<=i;j++)
{
a[j]=a[j+1];
}
i--;
}
else
{
printf("The no is not in list, Sorry\n");
}
}
void traversa()
{
int j;
for(j=0;j<=i;j++)
{
printf("%d\n",a[j]);
}

//Body of traversa function

}
void merged()
{
int p,q,m,n,c;
int array1[100],array2[100],array3[200];
puts("Enter number of element of the first sorted array");
scanf("%d",&p);
puts("Enter element of the first sorted array");
for(m=0;m<=p;m++)
scanf("%d",&array1[m]);
puts("Enter number of element of the second sorted array");
scanf("%d",&q);
puts("Enter element of the second array");
for(n=0;n<=q;n++)
scanf("%d",&array2[n]);

c=0;
m=0;
n=0;
while((m<q)&&(n<q))
{
if(array1[m]<=array2[n])
array3[c]=array1[m++];
else
array3[c]=array2[n++];
c++;
}
while(m<p)
{
array3[c]=array1[m];
c++;
m++;
}
while(n<q)
{
array3[c]=array2[n];
c++;
n++;
}
puts("merged array in ascending order");
for(m=0;m<=c;m++)
printf("%d\n",array3[m]);
}

Potrebbero piacerti anche