In this tutorial you will learn about the C Program to Perform Scalar Matrix Multiplication and its application with practical example.
C Program to Perform Scalar Matrix Multiplication
In this tutorial, we will learn to create a C program that will Perform Scalar Matrix Multiplication using C programming.
Prerequisites
Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
1. Declaring the variables for the program. 2. Taking the input size of matrix. 3. Taking the input elements of matrix. 4. Input multiplier number for the matrix<strong>. </strong>5. Multiply the elements in the matrix<strong>.</strong> 6. Printing the <strong>multiplied Matrix</strong>. 7. End Program. |
Program to Perform Scalar Matrix Multiplication:-
In this tutorial, we will Perform Scalar Matrix Multiplication. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrix. Now we will take the multiplication number from the user. Then we will multiply the matrix from the taken number using the for loop. Now we will print the matrix after multiplication using the print function.
Below is a C program to perform the scalar multiplication of the matrix.
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* C Program to Perform Scalar Matrix Multiplication */ #include<stdio.h> int main() { //declaring the required variable for the program. int row, column, rw, cl, Multiplication[10][10], Number; //Taking the input rows and column from the user printf("\n Please Enter Number of rw and cl\n"); scanf("%d %d", &row, &column); //Taking the element of the matrix printf("\n Please Enter the Matrix Elements \n"); for(rw = 0; rw < row; rw++) { for(cl = 0;cl < column;cl++) { scanf("%d", &Multiplication[rw][cl]); } } //Taking the multiplyer value printf("\n Please Enter the Multiplication Value : "); scanf("%d", &Number); //multiplication of the matrix. for(rw = 0; rw < row; rw++) { for(cl = 0; cl < column; cl++) { Multiplication[rw][cl] = Number * Multiplication[rw][cl]; } } //Printing the result of a Scalar Matrix Multiplication. printf("\n The Result of a Scalar Matrix Multiplication is : \n"); for(rw = 0; rw < row; rw++) { for(cl = 0; cl < column; cl++) { printf("%d \t ", Multiplication[rw][cl]); } printf("\n"); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- Multiplication [10][10] = it will hold the integer value.
- rw = it will hold the integer value for the loop.
- cl = it will hold the integer value for the loop.
- row = it will hold the input integer value for rows.
- Column = it will hold the input integer value for columns.
Taking the size and the elements of the matrix from the user and then the multiplier number.
Calculate the scalar multiplication of the matrix using a for loop.
Printing the multiplied matrix.