Adjoint of Matrix In C Language
Today i'm going to tell you about how to calculate the adjoint of matrix in C Language
{tocify} $title={Table of Contents}
First we will include
Header Files
#include<stdio.h>
#include<string.h>
Declare integers
which will be used while calculating the Adjoint of a Matrix.like: Data_type Variable_name1, Variable_name2, Variable_name 3, ........., Variable_nameN;
For e.g.
main()
{
int a11, a12, a13, a21, a22, a23, a31, a32, a33, b11, b12, b13, b21, b22, b23, b31, b32, b33,r11, r12, r13,r21, r22, r23, r31, r32, r33, c11, c12, c13, c21, c22, c23, c31, c32, c33 ;
}
Show a sample matrix
. According to which one can add the values of the matrix in the next step.printf("\n Enter the value as described in the demo matrix below for 1st matrix");
printf("\n\n Let the first matrix be A matrix \n Therefore, matrix be in the form :");
printf("\n\n A11 \t A12 \t A13");
printf("\n A21 \t A22 \t A23");
printf("\n A31 \t A32 \t A33");
printf("\n\n Compare the values of your matrix with the values of the above matrix and fill the below values");
code to Take values according to sample matrix
. Taking input from the user printf("\n\nEnter the value A11 : ");
scanf("%d",&a11);
printf("\nEnter the value A12 : ");
scanf("%d",&a12);
printf("\nEnter the value A13 : ");
scanf("%d",&a13);
printf("\nEnter the value A21 : ");
scanf("%d",&a21);
printf("\nEnter the value A22 : ");
scanf("%d",&a22);
printf("\nEnter the value A23 : ");
scanf("%d",&a23);
printf("\nEnter the value A31 : ");
scanf("%d",&a31);
printf("\nEnter the value A32 : ");
scanf("%d",&a32);
printf("\nEnter the value A33 : ");
scanf("%d",&a33);
Showing the output
Showing the output of the taken values so that the user can see whether the the matrix is right or wrong.If Right :
Then he can proceed
If Wrong:
Then Can Re-Run the program
printf("\n\n A = ");
printf("\n \t %d",a11);
printf(" \t %d",a12);
printf(" \t %d",a13);
printf("\n \t %d",a21);
printf(" \t %d",a22);
printf(" \t %d",a23);
printf("\n \t %d",a31);
printf(" \t %d",a32);
printf(" \t %d",a33);
calculate Cofactor matrix
. For calculating this cofactor matrix we need to add the below code in our program c11=a22*a33-a32*a23;
c12=-(a21*a33-a31*a23);
c13=a21*a32-a31*a22;
c21=-(a12*a33-a32*a13);
c22=a11*a33-a31*a13;
c23=-(a11*a32-a31*a12);
c31=a12*a23-a22*a13;
c32=-(a11*a23-a21*a13);
c33=a11*a22-a21*a12;
show Cofactor matrix
. For showing this cofactor matrix we need to add the below code in our programprintf("\n\ncofactor of A11 : %d",c11);
printf("\ncofactor of A12 : %d",c12);
printf("\ncofactor of A13 : %d",c13);
printf("\ncofactor of A21 : %d",c21);
printf("\ncofactor of A22 : %d",c22);
printf("\ncofactor of A23 : %d",c23);
printf("\ncofactor of A31 : %d",c31);
printf("\ncofactor of A32 : %d",c32);
printf("\ncofactor of A33 : %d",c33);
printf("\n\n\n Therefore, Cofactor matrix of A is i.e. Aij = ");
printf("\n\t \t \t \t%d",c11);
printf("\t %d",c12);
printf("\t %d",c13);
printf("\n\t \t \t \t%d",c21);
printf("\t %d",c22);
printf("\t %d",c23);
printf("\n\t\t\t \t%d",c31);
printf("\t %d",c32);
printf("\t %d",c33);
show Adjoint of matrix
. For showing Adjoint of matrix we need to add the below code in our programprintf("\n\n\n Therefore, Adjoint of Matrix A is :");
printf("\n\n\t \t%d",c11);
printf("\t %d",c21);
printf("\t %d",c31);
printf("\n\t \t%d",c12);
printf("\t %d",c22);
printf("\t %d",c32);
printf("\n\t \t%d",c13);
printf("\t %d",c23);
printf("\t %d",c33);
Resultant syntax/Algorithm of the Progam is:
/*Header Files*/
#include<stdio.h>
#include<string.h>
main()
{
int a11, a12, a13, a21, a22, a23, a31, a32, a33, b11, b12, b13, b21, b22, b23, b31, b32, b33,r11, r12, r13,r21, r22, r23, r31, r32, r33, c11, c12, c13, c21, c22, c23, c31, c32, c33 ;
printf("\n Enter the value as described in the demo matrix below for 1st matrix");
printf("\n\n Let the first matrix be A matrix \n Therefore, matrix be in the form :");
/* Sample matrix*/
printf("\n\n A11 \t A12 \t A13");
printf("\n A21 \t A22 \t A23");
printf("\n A31 \t A32 \t A33");
printf("\n\n Compare the values of your matrix with the values of the above matrix and fill the below values");
/*Printing and Scanning the values of matrix*/
printf("\n\nEnter the value A11 : ");
scanf("%d",&a11);
printf("\nEnter the value A12 : ");
scanf("%d",&a12);
printf("\nEnter the value A13 : ");
scanf("%d",&a13);
printf("\nEnter the value A21 : ");
scanf("%d",&a21);
printf("\nEnter the value A22 : ");
scanf("%d",&a22);
printf("\nEnter the value A23 : ");
scanf("%d",&a23);
printf("\nEnter the value A31 : ");
scanf("%d",&a31);
printf("\nEnter the value A32 : ");
scanf("%d",&a32);
printf("\nEnter the value A33 : ");
scanf("%d",&a33);
/*Showing The values of matrix filled by user*/
printf("\n\n A = ");
printf("\n \t %d",a11);
printf(" \t %d",a12);
printf(" \t %d",a13);
printf("\n \t %d",a21);
printf(" \t %d",a22);
printf(" \t %d",a23);
printf("\n \t %d",a31);
printf(" \t %d",a32);
printf(" \t %d",a33);
/* Formulae for the Result of Every value of Cofactor matrix i.e. c11 , c12, c13, c21, c22, c23. c31, c32, c33 etc.*/
c11=a22*a33-a32*a23;
c12=-(a21*a33-a31*a23);
c13=a21*a32-a31*a22;
c21=-(a12*a33-a32*a13);
c22=a11*a33-a31*a13;
c23=-(a11*a32-a31*a12);
c31=a12*a23-a22*a13;
c32=-(a11*a23-a21*a13);
c33=a11*a22-a21*a12;
/* Showing individual Result of Every value of Cofactor matrix i.e. c11 , c12, c13, c21, c22, c23. c31, c32, c33 etc.*/
printf("\n\ncofactor of A11 : %d",c11);
printf("\ncofactor of A12 : %d",c12);
printf("\ncofactor of A13 : %d",c13);
printf("\ncofactor of A21 : %d",c21);
printf("\ncofactor of A22 : %d",c22);
printf("\ncofactor of A23 : %d",c23);
printf("\ncofactor of A31 : %d",c31);
printf("\ncofactor of A32 : %d",c32);
printf("\ncofactor of A33 : %d",c33);
/*Result of Cofactor matrix*/
printf("\n\n\n Therefore, Cofactor matrix of A is i.e. Aij = ");
printf("\n\t \t \t \t%d",c11);
printf("\t %d",c12);
printf("\t %d",c13);
printf("\n\t \t \t \t%d",c21);
printf("\t %d",c22);
printf("\t %d",c23);
printf("\n\t\t\t \t%d",c31);
printf("\t %d",c32);
printf("\t %d",c33);
/*Adjoint of Matrix*/
printf("\n\n\n Therefore, Adjoint of Matrix A is :");
printf("\n\n\t \t%d",c11);
printf("\t %d",c21);
printf("\t %d",c31);
printf("\n\t \t%d",c12);
printf("\t %d",c22);
printf("\t %d",c32);
printf("\n\t \t%d",c13);
printf("\t %d",c23);
printf("\t %d",c33);
}
Sign | Description |
---|---|
<stdio.h> | Header File |
<string.h> | Header File |
int | integer (Data_Type) |
a11,...,c33 | Variable_name |
printf() | Displays the text |
scanf() | Scan the value of variable_name |
/* any text */ | Multi-Line comment |
%d | define the type of data to be printed on standard output. |
\n | start the next line |
\t | Used for Tab Space |
We Love Hearing from You!
Thank you for reading our post! Your thoughts and opinions are important to us. Please leave a comment below to share your feedback, ask questions, or start a discussion. We look forward to engaging with you!
Note: Comments are moderated to ensure a respectful and positive environment.