matrix...tower.. in c language
TRANSCRIPT
-
7/27/2019 Matrix...Tower.. in C Language
1/27
R.SIVARAMAN 1205174
PROGRAM:
//Tower of hanoi.
#include
#include
static unsigned int p;
int hanoi (int i,char x,char z,char y)
{
if(i==1)
{
cout
-
7/27/2019 Matrix...Tower.. in C Language
2/27
R.SIVARAMAN 1205174
}
OUTPUT:
Enter no. of disk: 3
Shift top disk from X to Y
Shift top disk from X to Z
Shift top disk from Y to Z
Minimum transition:3
SREC CBE -22
IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
3/27
-
7/27/2019 Matrix...Tower.. in C Language
4/27
R.SIVARAMAN 1205174
getch();
}
OUTPUT:
Enter no. of disk: 3
Shift top disk from X to Y
Shift top disk from X to Z
Shift top disk from Y to Z
Minimum transition 3
SREC CBE -22IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
5/27
R.SIVARAMAN 1205174
PROGRAM:
//Stack implementation.
#include
#include
int push(int stack[],int*top,int size)
{
int value;
if(*top>=size)
{
reurn(0);
}
else
{
printf(\nenter the element to be pushed);
scanf(%d,&value);
*top+=1;
stack[*top]=value;
return (stack[*top]);
}
}
int pop (int stack[],int*top)
{
int value;
if(*top
-
7/27/2019 Matrix...Tower.. in C Language
6/27
R.SIVARAMAN 1205174
}
else
{
value=stack[*top];
*top=*top-1;
}
return(value);
}
void display(int stack[],in t*top)
{
int i;
if(*top==-1);
{
printf(\nstack is empty );
}
else
{
printf(\nelement the stack are );
for(i=*top;i
-
7/27/2019 Matrix...Tower.. in C Language
7/27
R.SIVARAMAN 1205174
printf(\n1.push\n2.pop\n3.display4.quit\nenter your choice);
scanf(%d,&choice);
switch(choice)
{
case 1:
result=push(stack,&top,size)
if(result==0)
printf(\nstack full);
break;
case 2:
result=pop(stack,&top);
if(result==99)
printf(\nstack is empty);
else
printf(\nthe poped value is %d,result);
break;
case 3:
display(stack.&top);
break;
case 4:
exit();
}
printf(\nenter any key to continue:);
getch();
}while(choice);
}
-
7/27/2019 Matrix...Tower.. in C Language
8/27
R.SIVARAMAN 1205174
OUTPUT:
1.push
2.pop
3.display
4.quit
Enter your choice 1
Enter the element to br pushed 10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 2
The poped element is 10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 2
Stack is empty
Enter any key to continue
1.push
2.pop
-
7/27/2019 Matrix...Tower.. in C Language
9/27
R.SIVARAMAN 1205174
3.display
4.quit
Enter your choice 1
Enter the element to be pushed 10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 1
The element to be pushed 10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 4
SREC CBE -22IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
10/27
R.SIVARAMAN 1205174
PROGRAM:
//Stack implementation.
#include
#include
int push(int stack[],int*top,int size)
{
int value;
if(*top>=size)
{
reurn(0);
}
else
{
coutvalue;
*top+=1;
stack[*top]=value;
return (stack[*top]);
}
}
int pop (int stack[],int*top)
{
int value;
if(*top
-
7/27/2019 Matrix...Tower.. in C Language
11/27
R.SIVARAMAN 1205174
{
return(99);
}
else
{
value=stack[*top];
*top=*top-1;
}
return(value);
}
void display(int stack[],in t*top)
{
int i;
if(*top==-1);
{
cout
-
7/27/2019 Matrix...Tower.. in C Language
12/27
R.SIVARAMAN 1205174
do
{
coutchoice;
switch(choice)
{
case 1:
result=push(stack,&top,size)
if(result==0)
printf(\nstack full);
break;
case 2:
result=pop(stack,&top);
if(result==99)
cout
-
7/27/2019 Matrix...Tower.. in C Language
13/27
R.SIVARAMAN 1205174
OUTPUT:
1.push
2.pop
3.display
4.quit
Enter your choice 1
Enter the element to be pushed 10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 1
Enter the element to be pushed 20
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 1
Enter the element to be pushed 30
Enter any key to continue
-
7/27/2019 Matrix...Tower.. in C Language
14/27
R.SIVARAMAN 1205174
1.push
2.pop
3.display
4.quit
Enter your choice 1
Stack is full
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 3
The elements in the stack
30
20
10
Enter any key to continue
1.push
2.pop
3.display
4.quit
Enter your choice 4
SREC CBE -22IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
15/27
R.SIVARAMAN 1205174
PROGRAM:
//Arithmetic operations on Matrix.
#include
#include
int m,n,p,q,i,j,k,ch,x;
int a[10][10],b[10][10],c[10][10];
void add();
void sub();
void mul();
void main()
{
clrscr();
coutm>>n;
coutp>>q;
cout
-
7/27/2019 Matrix...Tower.. in C Language
16/27
R.SIVARAMAN 1205174
{
for(j=0;j>b[i][j];
}
}
do
{
cout
-
7/27/2019 Matrix...Tower.. in C Language
17/27
R.SIVARAMAN 1205174
}
else
{
cout
-
7/27/2019 Matrix...Tower.. in C Language
18/27
R.SIVARAMAN 1205174
{
for(j=0;j
-
7/27/2019 Matrix...Tower.. in C Language
19/27
R.SIVARAMAN 1205174
for(i=0;i
-
7/27/2019 Matrix...Tower.. in C Language
20/27
R.SIVARAMAN 1205174
2 1
Enter the value of B matrix 2
1 0
0 1
1.Addition
2.Subraction
3.Multiplication
Enter your choice 1
Addition of two matrix
2 2
2 2
Continue means enter 1 if not enter 0 :1
1.Addition
2.Subraction
3.Multiplication
Enter your choice 2
Subtraction of two matrix is
0 2
2 0
Continue means enter 1 if not enter 0 :1
1.Addition
2.Subraction
3.Multiplication
Enter your choice 3
Multiplication of two matrix is
1 2
2 1
Continue means enter 1 if not enter 0: 0
SREC CBE -22
IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
21/27
R.SIVARAMAN 1205174
PROGRAM:
//Arithmetic operations on matrix.
#include< stdio.h>
#include
int m,n,p,q,i,j,k,ch,x;
int a[10][10],b[10][10],c[10]120];
void add();
void sub();
void mul();
void main()
{
clrscr();
printf("\n Enter the rows and columns of A matrix:");
scanf(%d%d,&m,&n);
printf("\n Enter the rows and columns of B matrix:");
scanf(%d%d,&p,&q);
printf("\n Enter the value of A matrix:");
for(i=0;i
-
7/27/2019 Matrix...Tower.. in C Language
22/27
R.SIVARAMAN 1205174
for(i=0;i
-
7/27/2019 Matrix...Tower.. in C Language
23/27
R.SIVARAMAN 1205174
void sub();
}
else
{
printf("\n Subtraction of two matrix is impossible");
}
break;
case 3:
if(n==p)
{
void mul();
}
else
printf("\n Multiplication of two matrix is impossible");
break;
default:printf("\n Invalid choice");
}
printf("\n continue means enter 1 if not enter 0:");
scanf(%d,&x);
}
while(x==1);
getch();
}
void add()
{
printf("\n Addition of two matrix:");
-
7/27/2019 Matrix...Tower.. in C Language
24/27
R.SIVARAMAN 1205174
for(i=0;i
-
7/27/2019 Matrix...Tower.. in C Language
25/27
R.SIVARAMAN 1205174
Void mul()
{
printf("\n multiplication of two matrix:");
for(i=0;i
-
7/27/2019 Matrix...Tower.. in C Language
26/27
R.SIVARAMAN 1205174
Enter the value of A matrix 2
1 2
2 1
Enter the value of B matrix 2
1 0
0 1
1.Addition
2.Subraction
3.Multiplication
Enter your choice 1
Addition of two matrix
2 2
2 2
Continue means enter 1 if not enter 0: 1
1.Addition
2.Subraction
3.Multiplication
Enter your choice 2
Subtraction of two matrix is
0 2
2 0
Continue means enter 1 if not enter 0 :1
1.Addition
2.Subraction
3.Multiplication
SREC CBE -22
IT DEPT
NOMENCLATURE MARKS
PREPARATION(5)
OUTPUT(5)
VIVA(5)
RECORD(5)
TOTAL(20)
SIGN
-
7/27/2019 Matrix...Tower.. in C Language
27/27
R.SIVARAMAN 1205174
Enter your choice 3
Multiplication of two matrix is
1 2
2 1
Continue means enter 1 if not enter 0: 0