Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Program 12 12. Write A Program To Perform Multiplication of Matrices

The document describes a C program to multiply matrices. It defines two 3x3 matrices A and B, and a result matrix M. It then uses nested for loops to iterate through the matrices, calculating the sum of the products of corresponding elements to populate the result matrix M. The program then prints M to display the multiplied matrices.
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)
54 views5 pages

Program 12 12. Write A Program To Perform Multiplication of Matrices

The document describes a C program to multiply matrices. It defines two 3x3 matrices A and B, and a result matrix M. It then uses nested for loops to iterate through the matrices, calculating the sum of the products of corresponding elements to populate the result matrix M. The program then prints M to display the multiplied matrices.
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
You are on page 1/ 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-Mohit Marwaha
ENROLLMENT NO-10090202019
DATA STRUCTURE USING C

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

Output:

NAME-Mohit Marwaha
ENROLLMENT NO-10090202019
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-Mohit Marwaha
ENROLLMENT NO-10090202019
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-Mohit Marwaha
ENROLLMENT NO-10090202019
DATA STRUCTURE USING C

}Output :

NAME-Mohit Marwaha
ENROLLMENT NO-10090202019

You might also like