Assignment 8
Assignment 8
Assignment 8
1. Write a program in C to perform the following functions on two 2D arrays entered by user:
a) Addition of matrices
b) Multiplication of matrices
c) Transpose of matrix
#include <stdio.h>
void addMatrices(int rows, int cols, int mat1[rows][cols], int mat2[rows][cols], int result[rows][cols]) {
void multiplyMatrices(int rows1, int cols1, int mat1[rows1][cols1], int rows2, int cols2, int
mat2[rows2][cols2], int result[rows1][cols2]) {
result[i][j] = 0;
result[j][i] = mat[i][j];
printf("\n");
int main() {
printf("Enter the number of rows and columns for the first matrix: ");
printf("Enter the number of rows and columns for the second matrix: ");
if (cols1 != rows2) {
return 1;
}
scanf("%d", &mat1[i][j]);
scanf("%d", &mat2[i][j]);
// Perform addition
// Perform multiplication
return 0;
2. Write a program in C to take a number as input and find the factorial of this number using
functions.
#include <stdio.h>
int prod = 1;
prod = prod*i;
return prod;
int main(){
int num ;
printf("Enter the number\n");
scanf("%d", &num);
return 0;
3. Write a program in C to take a number as input and find the if the number is prime or not using
functions.
int main() {
int number;
scanf("%d", &number);
if (isPrime(number))
else
return 0;