You are on page 1of 5

DATA STRUCTURE USING C

PROGRAM 12
12. Write a program to perform multiplication of matrices.

#include<stdio.h>
#include<conio.h>
void main()
{
int A[3][3],B[3][3],M[3][3],I,j,k,sum=0;
printf(“Enter first 3*3 matrix elements :”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&A[i][j]);
}
printf(“Enter second 3*3 matrix element:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&B[i][j]);
}
//multipliying
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum=0;
for(k=0;k<3;k++)
sum=sum+A[i][k]*B[k][j];
M[i][j]=sum;
}
}
printf(“Multiplication result of the two given matrix : \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d \t”,M[i][j]);

NAME-RATI SINGH
ENROLLMENT NO-08590202019
DATA STRUCTURE USING C

}
printf(“\n”);
}
getch();
}

Output:

NAME-RATI SINGH
ENROLLMENT NO-08590202019
DATA STRUCTURE USING C

PROGRAM 13
13. Create a menu driven program to insert and delete an array at a specific
position.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int A[30],n,i;
void deletion();
void insertion();
void main()
{
clrscr();
int choice;
do
{
printf(“Choose for Deletion or Insertion\n”);
printf(“1. Insertion\n”);
printf(“2. Deletion\n”);
printf(“Enter your choice \n”);
scanf(“%d”,&choice);
switch(choice)
{
case 1 : insertion();
Break;
case 2 : deletion();
Break;
case 3 : exit(0);
Break;
default : printf(“Invalid choice\n”);
Break;
}
}while(choice!=3);
getch();
}

void insertion()

NAME-RATI SINGH
ENROLLMENT NO-08590202019
DATA STRUCTURE USING C

{
int pos;
int item=30;
printf(“Enter the size of the array\n”);
scanf(“%d”,&n);
printf(“Enter the elements of the array\n”);
for(i=0;i<n;i++)
scanf(“%d”,&A[i]);
printf(“Enter position where you want to insert item value\n”);
scanf(“%d”,&pos);
i=n-1;
while( i>=pos)
{
A[i+1]=A[i];
i--;
}
A[pos]=item;
printf(“Array after insertion of given n”);
for(i=0;i<n;i++)
printf(“%d\t\n”,A[i]);
}

void deletion()
{
int pos;
printf(“Enter the size of the array\n”);
scanf(“%d”,&n);
printf(“Enter the elements of the array now\n”);
for(i=0;i<n;i++)
scanf(“%d”,&A[i]);
printf(“Enter the position from where you want to delete element\n”);
scanf(“%d”,&pos);
for(i=pos-1;i<n-1;i++)
A[i]=A[i+1];
printf(“Array after deletion of element from given position\n”);
for(i=0;i<n-1;i++)
printf(“%d\n”,A[i]);

NAME-RATI SINGH
ENROLLMENT NO-08590202019
DATA STRUCTURE USING C

}Output :

NAME-RATI SINGH
ENROLLMENT NO-08590202019

You might also like