0% found this document useful (0 votes)
32 views2 pages

Matrix Addition

The document contains a C program for matrix addition, including functions to read, print, and add two matrices. It prompts the user for the dimensions and elements of the matrices, performs the addition, and displays the resultant matrix. The program utilizes a 10x10 matrix size limit and includes standard input/output functions.

Uploaded by

highonmeth890
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)
32 views2 pages

Matrix Addition

The document contains a C program for matrix addition, including functions to read, print, and add two matrices. It prompts the user for the dimensions and elements of the matrices, performs the addition, and displays the resultant matrix. The program utilizes a 10x10 matrix size limit and includes standard input/output functions.

Uploaded by

highonmeth890
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/ 2

Matrix Addition

#include <stdio.h>
#include<conio.h>
void readMatrix(int matrix[10][10], int rows, int cols)
{
int i,j;
printf("Enter elements of the matrix (%d x %d):\n", rows, cols);
for(i =0;i<rows;i++)
{
for(j =0;j<cols;j++)
{
printf("Element [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
}
void printMatrix(int matrix[10][10], int rows, int cols)
{
int i,j;
printf("Matrix:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
}
void addMatrices(int A[10][10], int B[10][10], int result[10][10], int rows, int cols)
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
result[i][j] = A[i][j] + B[i][j];
}
}
}
void main()
{
int A[10][10], B[10][10], result[10][10];
int rows, cols;
clrscr();
printf("Enter the number of rows and columns of the matrices: ");
scanf("%d %d", &rows, &cols);
printf("Enter elements of first matrix:\n");
readMatrix(A, rows, cols);
printf("Enter elements of second matrix:\n");
readMatrix(B, rows, cols);
addMatrices(A, B, result, rows, cols);
printf("Resultant Matrix after Addition:\n");
printMatrix(result, rows, cols);
getch();
}

You might also like