This is a C Program to find the volume of tetrahedron.

Call the four vertices of the tetrahedron (a, b, c), (d, e, f), (g, h, i), and (p, q, r). Now create a 4-by-4 matrix in which the coordinate triples form the colums of the matrix, with a row of 1’s appended at the bottom:

a d g p

b e h q

c f i r

1 1 1 1

The volume of the tetrahedron is 1/6 times the absolute value of the matrix determinant. For any 4-by-4 matrix that has a row of 1’s along the bottom, you can compute the determinant with a simplification formula that reduces the problem to a 3-by-3 matrix

a-p d-p g-p

b-q e-q h-q

c-r f-r i-r

Call the four vertices of the tetrahedron (a, b, c), (d, e, f), (g, h, i), and (p, q, r). Now create a 4-by-4 matrix in which the coordinate triples form the colums of the matrix, with a row of 1’s appended at the bottom:

a d g p

b e h q

c f i r

1 1 1 1

The volume of the tetrahedron is 1/6 times the absolute value of the matrix determinant. For any 4-by-4 matrix that has a row of 1’s along the bottom, you can compute the determinant with a simplification formula that reduces the problem to a 3-by-3 matrix

a-p d-p g-p

b-q e-q h-q

c-r f-r i-r

Here is source code of the C Program to Compute the Volume of a Tetrahedron Using Determinants. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`#include <string.h>`

`#include <stdio.h>`

`#include <stdlib.h>`

int i, j, c;

double det(int n, double mat[3][3]) {

double submat[3][3];

float d;

for (c = 0; c < n; c++) {

int subi = 0; //submatrix's i value

for (i = 1; i < n; i++) {

int subj = 0;

for (j = 0; j < n; j++) {

if (j == c)

continue;

submat[subi][subj] = mat[i][j];

`subj++;`

`}`

`subi++;`

`}`

d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));

`}`

return d;

`}`

int main(int argc, char **argv) {

printf("Enter the points of the triangle:\n");

int x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4;

scanf("%d", &x1);

scanf("%d", &y1);

scanf("%d", &z1);

scanf("%d", &x2);

scanf("%d", &y2);

scanf("%d", &z2);

scanf("%d", &x3);

scanf("%d", &y3);

scanf("%d", &z3);

scanf("%d", &x4);

scanf("%d", &y4);

scanf("%d", &z4);

double mat[4][4];

mat[0][0] = x1;

mat[0][1] = x2;

mat[0][2] = x3;

mat[0][3] = x4;

mat[1][0] = y1;

mat[1][1] = y2;

mat[1][2] = y3;

mat[1][3] = y4;

mat[2][0] = z1;

mat[2][1] = z2;

mat[2][2] = z3;

mat[2][3] = z4;

mat[3][0] = 1;

mat[3][1] = 1;

mat[3][2] = 1;

mat[3][3] = 1;

printf("\nMatrix formed by the points: \n");

for (i = 0; i < 4; i++) {

for (j = 0; j < 4; j++) {

printf("%lf ", mat[i][j]);

`}`

printf("\n");

`}`

double matrix[3][3];

matrix[0][0] = x1 - x4;

matrix[0][1] = x2 - x4;

matrix[0][2] = x3 - x4;

matrix[1][0] = y1 - y4;

matrix[1][1] = y2 - y4;

matrix[1][2] = y3 - y4;

matrix[2][0] = z1 - z4;

matrix[2][1] = z2 - z4;

matrix[2][2] = z3 - z4;

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

printf("%lf ", mat[i][j]);

`}`

printf("\n");

`}`

float determinant = det(3, matrix) / 6;

if (determinant < 0)

printf("The area of tetrahedron formed by (%d, %d, %d), (%d, %d, %d), (%d, %d, %d), (%d, %d, %d) = %lf ",

x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4,

(determinant * -1));

`else`

printf("The area of tetrahedron formed by (%d, %d, %d), (%d, %d, %d), (%d, %d, %d), (%d, %d, %d) = %lf ",

x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, determinant);

return 0;

`}`

Output:

$ gcc TetrahedronVolume.c $ ./a.out Enter the points of the triangle: 0 9 6 0 4 2 1 1 3 4 7 5 Matrix formed by the points: 0 9 6 0 4 2 1 1 3 4 7 5 1 1 1 1 0 9 6 3 1 0 -2 -1 2 The Area of the tetrahedron formed by (0,4,3), (9,2,4), (6,1,7), (0,1,5) = 10.0

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.