Program of Matrix Multiplication: Lab Practical No. - 1
Program of Matrix Multiplication: Lab Practical No. - 1
– 1
n = a[0][1];
terms = a[0][2];
b[0][0] = n;
b[0][1] = a[0][0];
b[0][2] = terms;
c[0][0] = a[0][0];
c[0][1] = b[0][1];
// init c.
for( i=0; i<=mn; ++i )
c[i][2] = 0;
// fill t[] : t[i] points to row of b where actual row i
starts.
// last+1 entry is also maintained for easing loops.
for( i=0; i<=rowsofb; ++i )
t[i] = 0;
for( i=1; i<=bterms; ++i )
t[b[i][0]]++;
temp = t[0];
t[0] = 1;
for( i=1; i<=rowsofb; ++i )
temp2 = t[i], t[i] = t[i-1]+temp, temp = temp2;
int main() {
int a[][3] = {
{4,2,3},
{0,1,2},
{1,0,3},
{3,1,4}
};
int b[][3] = {
{2,3,3},
{0,2,5},
{1,0,7},
{1,1,6}
};
int c[M*N+1][3];
printMatrix(a);
printMatrix(b);
mmult( a, b, c );
printMatrix(c);
return 0;
}
Lab Practical No. – 2
void main()
{
int list[MAX], n, element;
printf("Enter the number of elements in the list max = 10\n");
scanf("%d",&n);
readlist(list,n);
printf("\nThe list before sorting is:\n");
printlist(list,n);
printf("\nEnter the element to be searched\n");
scanf("%d",&element);
bsearch(list,n,element);
}
void main()
{
int list[MAX], n;
printf("Enter the number of elements in the list max = 10\n");
scanf("%d",&n);
readlist(list,n);
printf("The list before sorting is:\n");
printlist(list,n);
msort(list,n-1);
printf("The list after sorting is:\n");
printlist(list,n);
}
void main()
{
int list[MAX], n;
printf("Enter the number of elements in the list max = 10\n");
scanf("%d",&n);
readlist(list,n);
printf("The list before sorting is:\n");
printlist(list,n);
qsort(list,0,n-1);
printf("\nThe list after sorting is:\n");
printlist(list,n);
}
void main()
{
int list[MAX], n;
printf("Enter the number of elements in the list max = 10\n");
scanf("%d",&n);
readlist(list,n);
printf("The list before sorting is:\n");
printlist(list,n);
heapsort(list,n);
printf("The list after sorting is:\n");
printlist(list,n);
}
if(p==NULL)
{
printf("Error\n");
exit(0);
}
p-> data = n;
p-> link = p; /* makes the pointer pointing to itself
because it
is a circular list*/
}
else
{
temp = p;
/* traverses the existing list to get the pointer to the last
node of
it */
while (temp-> link != p)
temp = temp-> link;
temp-> link = (struct node *)malloc(sizeof(struct
node)); /*
creates new node using
data value passes as
parameter and puts its
address in the link field
of last node of the
existing list*/
if(temp -> link == NULL)
{
printf("Error\n");
exit(0);
}
temp = temp-> link;
temp-> data = n;
temp-> link = p;
}
return (p);
}
void printlist ( struct node *p )
{
struct node *temp;
temp = p;
printf("The data values in the list are\n");
if(p!= NULL)
{
do
{
printf("%d\t",temp->data);
temp=temp->link;
} while (temp!= p);
}
else
printf("The list is empty\n");
}
void main()
{
int n;
int x;
struct node *start = NULL ;
printf("Enter the nodes to be created \n");
scanf("%d",&n);
while ( n -- > 0 )
{
printf( "Enter the data values to be placed in a node\n");
scanf("%d",&x);
start = insert ( start, x );
}
printf("The created list is\n");
printlist ( start );
}
Lab Practical No. – 9
if(p==NULL)
{
printf("Error\n");
exit(0);
}
p->data = n;
p-> left = p->right =NULL;
*q =p;
}
else
{
temp = (struct dnode *)malloc(sizeof(struct dnode));
/* creates new node using data value passed as parameter and puts
its address in the temp */
if(temp == NULL)
{
printf("Error\n");
exit(0);
}
temp->data = n;
temp->left = (*q);
temp->right = NULL;
(*q)->right = temp;
(*q) = temp;
}
return (p);
}
void printfor( struct dnode *p )
{
printf("The data values in the list in the forward order
are:\n");
while (p!= NULL)
{
printf("%d\t",p-> data);
p = p->right;
}
}
void printrev( struct dnode *p )
{
printf("The data values in the list in the reverse order
are:\n");
while (p!= NULL)
{
printf("%d\t",p->data);
p = p->left;
}
}
void main()
{
int n;
int x;
struct dnode *start = NULL ;
struct dnode *end = NULL;
printf("Enter the nodes to be created \n");
scanf("%d",&n);
while ( n-- > 0 )
{
printf( "Enter the data values to be placed in a node\n");
scanf("%d",&x);
start = insert ( start, &end,x );
}
printf("The created list is\n");
printfor ( start );
printrev(end);
}
void main()
{
int stack[MAX];
int top = -1;
int n,value;
do
{
do
{
printf("Enter the element to be pushed\n");
scanf("%d",&value);
push(stack,&top,value);
printf("Enter 1 to continue\n");
scanf("%d",&n);
} while(n == 1);
void main()
{
struct node *front=NULL,*rear = NULL;
int n,value;
do
{
do
{
printf("Enter the element to be inserted\n");
scanf("%d",&value);
insert(&front,&rear,value);
printf("Enter 1 to continue\n");
scanf("%d",&n);
} while(n == 1);
else
{
temp1 = *front;
while((temp1->link)->priority >= priority)
/* find the position and insert the new element */
temp1=temp1->link;
temp->link = temp1->link;
temp1->link = temp;
}
}
void delete(struct node **front, struct node **rear, int *value,
int *priority)
{
struct node *temp;
if((*front == *rear) && (*rear == NULL))
{
printf(" The queue is empty cannot delete Error\n");
exit(0);
}
*value = (*front)->data;
*priority = (*front)->priority;
temp = *front;
*front = (*front)->link;
if(*rear == temp)
*rear = (*rear)->link;
free(temp);
}
void main()
{
struct node *front=NULL,*rear = NULL;
int n,value, priority;
do
{
do
{
printf("Enter the element to be inserted and its
priority\n");
scanf("%d %d",&value,&priority);
insert(&front,&rear,value,priority);
printf("Enter 1 to continue\n");
scanf("%d",&n);
} while(n == 1);
void main()
{
int queue[MAX];
int front,rear;
int n,value;
front=0; rear=0;
do
{
do
{
printf("Enter the element to be inserted\n");
scanf("%d",&value);
insert(queue,&rear,front,value);
printf("Enter 1 to continue\n");
scanf("%d",&n);
} while(n == 1);
#define N 80
#include "stack.h"
#include "queue.h"
#define NOPS 7
tptr = t;
for( sptr=str+strlen(str)−1; sptr!=str−1; -sptr ) {
printf( "processing %c tptr-t=%d...\n", *sptr, tptr-t );
if( isalpha(*sptr) ) // if operand.
qPush( &q, *sptr );
else if( isop(*sptr) ) // if valid operator.
processOp( *sptr, &q, &s );
else if( isspace(*sptr) ) // if whitespace.
;
else {
fprintf( stderr, "ERROR:invalid char %c.\n",
*sptr );
return "";
}
}
while( !qEmpty(&q) ) {
*tptr++ = qPop(&q);
printf( "\tQ popping %c...\n", *(tptr-1) );
}
while( !sEmpty(&s) ) {
*tptr++ = sPop(&s);
printf( "\tS popping %c...\n", *(tptr-1) );
}
*tptr = 0;
printf( "t=%s.\n", t );
for( -tptr; tptr!=t−1; -tptr ) {
*resptr++ = *tptr;
}
*resptr = 0;
return res;
}
int main() {
char s[N];
return 0;
}
scanf("%d",&adj[i][j]);
}
}
/* a function to visit the nodes in a depth-first order */
void dfs(int x,int visited[],int adj[][max],int n)
{
int j;
visited[x] = 1;
printf("The node visited id %d\n",x);
for(j=0;j<n;j++)
if(adj[x][j] ==1 && visited[j] ==0)
dfs(j,visited,adj,n);
}
void main()
{
int adj[max][max],node,n;
int i, visited[max];
printf("enter the number of nodes in graph maximum =
%d\n",max);
scanf("%d",&n);
buildadjm(adj,n);
for(i=0; i<n; i++)
visited[i] =0;
for(i=0; i<n; i++)
if(visited[i] ==0)
dfs(i,visited,adj,n);
}