You are on page 1of 9

Ex no: 11

20-02-2012

MULTIPLICATION OF 2D ARRAY

CODING:
#include<stdio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j,k;
printf("Enter the first matrix elements:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("Enter the second matrix elements:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
printf("The multiplication of two matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][i];
}
printf("\t");
printf("%d",c[i][j]);
}
printf("\n");
}
}
OUTPUT:
Enter the first matrix elements:
1
2
3
4
5
6
7
8
9
Enter the second matrix elements:
9
8
7
6
5
4
3
2
1
The multiplication of two matrix is:
30
30
30
69
69
69
90
90
90

RESULT:
A program was created and implemented for multiplying two matrices.
Ex no: 12
20-02-2012
FIBONACCI SERIES
CODING:
#include<stdio.h>
int fib(int a, int b, int c, int n);
main()
{
int a=-1,b=1,c=0,n;
printf( Enter a number : );
scanf("%d",&n);
printf("Fibonacci series is");
fib(a,b,c,n);
}
int fib(int a, int b, int c, int n)
{
if ( n == 0 )
return 0;
else
{
c=a+b;
a=b;
b=c;
printf( %d\n ,c);
fib(a,b,c,n);
}
}

OUTPUT:
Enter a number : 10
Fibonacci series is
0
1
1
2
3
5
8
13
21
34

RESULT:
A program was created and implemented for printing Fibonacci series numb
ers using the concept of recursive.
Ex no: 13
23-02-2012
IMPLEMENTATION OF 3D ARRAY
CODING:
#include <stdio.h>
int a[5][5][5],i,j,k;
int num,qty,pri;
void input();
void display();
void calc();
main()
{
int ch;
input();
do
{
printf("\n\t1.Details\n\t2.Purchase\n\t3.Exit\nEnter your Choice: ");
scanf ("%d",&ch);
switch (ch)
{
case 1:
display();
break;
case 2:
calc();
break;
}
}while(ch!=3);
}
void input()
{
for(i=0;i<5;i++)
{
printf ("\n%d\nEnter the Item no, Qty, Rate : ");
for(j=0;j<3;j++)
{
for(k=0;k<1;k++)
{
scanf ("%d",&a[i][j][k]);
}
}printf("\n");
}
}
void display()

{
printf ("\n\t\t\tITEM DETAILS\n\n");
printf ("\n\tItem no\t\tQuantity\t\tRate\n");
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<1;k++)
printf ("\t%d\t",a[i][j][k]);
}
printf ("\n\n");
}
}
void calc()
{
printf("\n\t\t\tITEM PURCHASING");
printf("\n Enter the item number:");
scanf("%d",&num);
for(i=0;i<5;i++)
{
if(a[i][0][0]==num)
{
printf("\n Item is available...\nEnter the quantity needed:");
scanf("%d",&qty);
break;
}
else
continue;
}
if(a[i][1][0]>=qty)
{
pri=qty*a[i][2][0];
printf("\nPrice of %d items is : Rs.%d/-\n\n",qty,pri);
a[i][1][0]-=qty;
}
else
printf("\nExpected Quatity not Available...\n Sorry...\n\n");
}
OUTPUT:
Enter the
Enter the
Enter the
Enter the
Enter the

item
item
item
item
item

no,
no,
no,
no,
no,

Qty,
Qty,
Qty,
Qty,
Qty,

Rate:1
Rate:2
Rate:3
Rate:4
Rate:5

6 54
9 78
4 98
12 65
7 66

1.Details
2.Purchase
3.Exit
Enter your choice:1
ITEM DETAILS
Item no
1
2
3
4
5
1.Details
2.Purchase

Qty

Rate
6
9
4
12
7

54
78
98
65
66

3.Exit
Enter your choice:2
ITEM PURCHASING
Enter the item number: 3
Item is available...
Enter the quantity needed: 3
Price of 3 items is: Rs.294/1.Details
2.Purchase
3.Exit
Enter your choice:1
ITEM DETAILS
Item no
1
2
3
4
5

Qty

Rate
6
9
1
12
7

54
78
98
65
66

1.Details
2.Purchase
3.Exit
Enter your choice:3

RESULT:
A program was created and implemented for print purchase details using 3
D array.
Ex no: 14
01-03-2012
INFIX TO POSTFIX CONVERSION
CODING:
#include<stdio.h>
main()
{
char exp[25];
int br[10],br2[10];
int op[10];
int i,j,k,l1,l2,t1,t2,n;
printf("\nEnter the expression string\n");
scanf("%s",exp);
for (i=0,j=0,k=0,n=0; exp[i]!='\0'; i++)
{
if (exp[i] == '(')
{
br[j] = i;
j++;
}
else if (exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/')
{
op[k] = i;
k++;
}
else if(exp[i]==')')
{

br2[n]=i;
l1 = br2[n];
l2 = op[k-1];
exp[l1] = exp[l2];
l1--;
for (;l1>=l2;l2++)
exp[l2] = exp[l2+1];
exp[l2-1] = ')';
n++;
k++;
}
printf("\nAfter %d iteration : %s",i+1,exp);
}
printf("\nPostfix string is %s",exp);
}
OUTPUT:
Enter the expression string: ((2*6)+(8*5))
After
After
After
After
After
After
After
After
After
After
After
After
After

1 iteration: ((2*6)+(8*5))
2 iteration: ((2*6)+(8*5))
3 iteration: ((2*6)+(8*5))
4 iteration: ((2*6)+(8*5))
5 iteration: ((2*6)+(8*5))
6 iteration: ((26)*+(8*5))
7 iteration: ((26)*+(8*5))
8 iteration: ((26)*+(8*5))
9 iteration: ((26)*+(8*5))
10 iteration: ((26)*+(8*5))
11 iteration: ((26)*+(8*5))
12 iteration: ((26)*+(85)*)
13 iteration: ((26)*(85)*+)

Postfix string is: ((26)*(85)*+)

RESULT:
A program was implemented for convert infix express to a postfix express
ion.
Ex no: 15
01-03-2012
EVALUATION OF POSTFIX EXPRESSION
CODING:
#include<stdio.h>
main()
{
char exp[25];
int br[10],br2[10];
int op[10];
int i,j,k,l1,l2,t1,t2,n;
printf("\nEnter the expression string\n");
scanf("%s",exp);
for (i=0,j=0,k=0,n=0; exp[i]!='\0'; i++)
{
if (exp[i] == '(')
{
br[j] = i;

j++;
}
else if (exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/')
{
op[k] = i;
k++;
}
else if(exp[i]==')')
{
br2[n]=i;
l1 = br2[n];
l2 = op[k-1];
exp[l1] = exp[l2];
l1--;
for (;l1>=l2;l2++)
exp[l2] = exp[l2+1];
exp[l2-1] = ')';
n++;
k++;
}
printf("\nAfter %d iteration : %s",i+1,exp);
}
printf("\nPostfix string is %s",exp);
}
OUTPUT:
Enter the expression string: ((2*6)+(8*5))
After
After
After
After
After
After
After
After
After
After
After
After
After

1 iteration: ((2*6)+(8*5))
2 iteration: ((2*6)+(8*5))
3 iteration: ((2*6)+(8*5))
4 iteration: ((2*6)+(8*5))
5 iteration: ((2*6)+(8*5))
6 iteration: ((26)*+(8*5))
7 iteration: ((26)*+(8*5))
8 iteration: ((26)*+(8*5))
9 iteration: ((26)*+(8*5))
10 iteration: ((26)*+(8*5))
11 iteration: ((26)*+(8*5))
12 iteration: ((26)*+(85)*)
13 iteration: ((26)*(85)*+)

Postfix string is: ((26)*(85)*+)

Ex no: 16
05-03-2012

Towers of Hanoi

CODING:
#include<stdio.h>
main()
{
void tower(int n,char source,char dest,char auxilary);
int numdisk;
printf("\n Enter the number of disks: ");

scanf("%d",&numdisk);
printf("\t\t\tSTART TOWER OF HANOI");
tower(numdisk,'a','b','c');
}
void tower(int n,char source,char dest,char auxilary)
{
if(n==1)
{
printf("\n\tMOVE FROM %c TO %c\n",source,dest);
}
else
{
tower(n-1,source,auxilary,dest);
printf("\n\tMOVE FROM %c TO %c\n",source,dest);
tower(n-1,auxilary,dest,source);
}
}
OUTPUT:
Enter the number of disks:2
START OF TOWER OF HANOI
MOVE FROM a TO c
MOVE FROM a TO b
MOVE FROM c TO b
RESULT:

Ex no: 17
05-03-2012

ACKERMANN

CODING:
#include<stdio.h>
int m,n,h;
main()
{
printf("Enter the value of M and N: ");
scanf("%d%d",&m,&n);
acker(m,n);
display(m,n);
}
acker(int m,int n)
{
if(m==0&&n!=0)
{
h=n+1;
}
else if(m!=0&&n==0)
{
acker(m-1,1);
}
else if(m!=0&&n!=0)
{
acker(m-1,acker(m,n-1));

}
}
display(int m,int n)
{
printf("A(%d,%d)=%d\n",m,n,h);
}

OUTPUT:
Enter the value of M and N:1 1
A(1,1)=3
RESULT:

You might also like