Category Archives: C Programs

C Programs

C Program to Determinant of a Matrix

C Program to Determinant of a Matrix

In this tutorial, we will learn to create a C program that will Find the Determinant of a Matrix 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.

What is a Determinant?

The Determinant is a calculated number from the matrix. For calculating the determinant, a matrix needs to be in a square format it means  2X2, 3X3.

Program to Find the Determinant of a Matrix:-

In this tutorial, we will find the Determinant of a Matrix. First, we will take the input elements of the matrix. Then we will print the input matrix to the user. Then we will find the determinant of the matrix form using the arithmetic expression. At last, we will print the output of the matrix to the user.

Below is a C program to find the sum of each row and every column in a matrix.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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 elements of the matrix from the user.

Calculating the Determinant in the matrix using a loop and a mathematical expression.

Printing the Determinant of a matrix.

C Program to Perform Scalar Matrix Multiplication

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:-

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:-

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.

C Program to Find Sum of each and every Row and Column in a Matrix

C Program to Find Sum of each and every Row and Column in a Matrix

In this tutorial, we will learn to create a C program that will Find the Sum of each row and column in a Matrix 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:-

Program to find the Sum of each and every Row and Column in a Matrix:-

In this tutorial, we will find the Sum of each row and every column in a Matrix. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrices. Now we will use the for loop to add the values of rows of that matrix, as well as adding the elements of the columns. At last, we will print the result matrix row and the column values after adding.

Below is a C program to find the sum of each row and every column in a matrix.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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.

Calculating the Sum of each ROW and every COLUMN in the matrix using a for loop.

Printing the Sum of each Row in a matrix.

Printing the Sum of every Column in a column.

C Program to Find sum of each row in a Matrix

C Program to Find Sum of each row in a Matrix

In this tutorial, we will learn to create a C program that will Find the Sum of each row in a Matrix 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:-

Program to find the Sum of each row in a Matrix:-

In today’s tutorial, we will find the Sum of each row in a Matrix. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrices. Now we will use the for loop to add the values of rows of that matrix. At last, we will print the result matrix row values after adding.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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.

Adding the Sum of each row in the matrix using a for loop.

Printing the Sum of rows of the matrix.

C Program to Find Sum of each column in a Matrix

C Program to Find Sum of each column in a Matrix

In this tutorial, we will learn to create a C program that will Find the Sum of each column in a Matrix 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:-

Program to find Sum of each column in a Matrix:-

In today’s tutorial, we will find the Sum of each column in a Matrix. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrices. Now we will use the for loop to add the values of columns of that matrix. At last, we will print the result matrix column values after adding.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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.

Adding the Sum of each column in the matrix using a for loop.

Printing the Sum of columns of the matrix.

C Program to add two Matrices

C Program to Add Two Matrices

In this tutorial, we will learn to create a C program that will add Two Matrices 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:-

Program to add Two Matrices:-

In today’s tutorial, we will add two matrices. First, we will take the size of the matrix from the user, and then we will take the input elements of the two matrices. Now we will add the two elements of the matrices. At last, we will print the result matrix after adding.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the two matrices from the user.

Adding the matrices one from another.

Printing the matrix after adding.

C Program to Subtract Two Matrices

C Program to Subtract Two Matrices

In this tutorial, we will learn to create a C program that will Subtract Two Matrices 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:-

Program to Subtract Two Matrices:-

In today’s tutorial, we will subtract two matrices. First, we will take the size of the matrix from the user, and then we will take the input elements of the two matrices. Now we will subtract the two elements of the matrices. At last, we will print the result matrix after subtracting.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[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.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the two matrices from the user.

Subtracting the matrices one from another.

Printing the matrix after subtracting.

C Program to Interchange Diagonals of a Matrix

C Program to Interchange Diagonals of a Matrix

In this tutorial, we will learn to create a C program that will Interchange Diagonals of a Matrix 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:-

Below is an example of the matrix before interchanging of diagonals figure1

Figure1

Then After interchanging of diagonals of the matrix is given below.

Figure 2

With the help of this program, we can Interchange the Diagonals of a Matrix.

Program to Interchange Diagonals of a Matrix:-

In this tutorial, we will interchange Diagonal Elements in a Matrix. 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 swap the diagonal elements in the matrix. At last, we will print the result matrix to the user.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value for the loop.
  • y = it will hold the integer value for the loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Interchanging the elements of the diagonals of the matrix.

Printing the matrix after interchanging the elements of the Matrix.

C Program to find Lower Triangle Matrix

C Program to find Lower Triangle Matrix

In this tutorial, we will learn to create a C program that will find the Lower Triangle Matrix 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.

What is a matrix?

A matrix is a multidimensional phenomenon and is created with the help of a 2d array having multiple rows and columns.

Algorithm:-

With the help of this program, we can find Lower Triangle Matrix.

Program to find Lower Triangle Matrix:-

In this tutorial, we will create a multidimensional array with the help of C programming. First, we will take the size of the matrix from the user, and then we will take the input elements. Now we will create a Lower triangle in the matrix by adding a zero in rows from the right corners. At last, we will print the lower matrix triangle.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value.
  • z = it will hold the integer value.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Creating the Lower triangle from the matrix.

Printing the Lower Triangle Matrix.

C Program to Check Matrix is a Sparse Matrix

C Program to Check Matrix is a Sparse Matrix

In this tutorial, we will learn to create a C program that will check the Matrix is a Sparse Matrix 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:-

Program to check the Matrix is a Sparse:-

In this tutorial, we will check the matrix is sparse or not with the help of c programming. First, we will take the size and the elements of the matrix. Then we will check the matrix is Sparse or not using the for loop and the conditional statements. Then will print the output after checking the matrix to the user using the print function.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value for the loop.
  • y = it will hold the integer value for the loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Checking the matrix is sparse or not.

Printing the Matrix is Sparse or not.

C Program to check Matrix is an Identity Matrix

C Program to check Matrix is an Identity Matrix

In this tutorial, we will learn to create a C program that will check the Matrix is an Identity Matrix 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:-

Program to check the Matrix is an Identity Matrix:-

In this tutorial, we will check the matrix is the identity matrix or not with the help of the c programming. First, we will take the size and the elements of the matrix. Then we will check the matrix is an identity or not using the for loop and the conditional statements. Then will print the output to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value for the loop.
  • y = it will hold the integer value for the loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the two matrices from the user.

Checking the Matrix is an Identity Matrix or not.

Printing the Matrix is an Identity Matrix or not.

C Program to find Sum of Diagonal Elements of a Matrix

C Program to Find Sum of Diagonal Elements in a Matrix

In this tutorial, we will learn to create a C program that will find the Sum of Diagonal Elements in a Matrix 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:-

With the help of this program, we can find the Sum of Diagonal Elements in a Matrix.

Program to find Sum of Diagonal Elements in a Matrix:-

In this tutorial, we will find the Sum of Diagonal Elements in a Matrix. 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 find the sum of the diagonal elements in the matrix. At last, we will find the sum of the diagonal elements of the matrix. Then we will print the result to the user.

Program:-

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value for loop.
  • y = it will hold the integer value for loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Adding the diagonal elements of the matrix.

Printing the Sum of diagonal elements of the Matrix.