Write a C program to find the determinant of the given matrix

/**
 * Calculates the determinant of a 2x2 matrix
 * using a function.
 */

#include<stdio.h>

int determinant(int a[2][2]);
int getInput(int matrix[][2], int row, int col);

main()
{


    int matrix[2][2], n, i, j;
    printf("Enter a 2x2 matrix: \n");
    getInput(matrix, 2, 2);
    printf("\n>>> Determinant: %d\n", determinant(matrix));
}

int getInput(int matrix[][2], int row, int col) {
    int i, j;
    for (i = 0; i < row; i++) {
        for (j = 0; j < col; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }
}

int determinant(int a[2][2]) {
    return a[0][0] * a[1][1] - a[1][0] * a[0][1];
}

Comments