0% found this document useful (0 votes)
19 views5 pages

Matrix Multiplication in C Program

The document describes two C programs. The first program multiplies two 3x3 matrices by taking user input for the elements, initializing arrays to store the matrices, and using a nested for loop to calculate the product sum and store it in a third array. The second program creates a menu-driven array program that allows the user to insert or delete elements from an array at a specified position using functions for insertion and deletion that shift the elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Matrix Multiplication in C Program

The document describes two C programs. The first program multiplies two 3x3 matrices by taking user input for the elements, initializing arrays to store the matrices, and using a nested for loop to calculate the product sum and store it in a third array. The second program creates a menu-driven array program that allows the user to insert or delete elements from an array at a specified position using functions for insertion and deletion that shift the elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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