home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch9 / determ.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  34 lines

  1. /*                      determ.c
  2.  *
  3.  *   Synopsis  - Accepts input of elements for a 2 x 2 matrix 
  4.  *               and calculates its determinant.
  5.  *   Objective - To show the basics of two-dimensional arrays.
  6.  */
  7.  
  8. /* Include Files */
  9. #include <stdio.h>
  10.  
  11. /* Constant Definitions */
  12. #define ROWS         2
  13. #define COLUMNS      2
  14.  
  15. int main( void )
  16. {
  17.      int i, j;
  18.      float m[ROWS][COLUMNS], determinant;             /* Note 1 */
  19.  
  20.      printf( "Calculate the determinant of a 2x2 matrix.\n" );
  21.      printf( "--------- --- ----------- -- - --- -------\n" );
  22.  
  23.      printf("\nEnter the matrix now.\n");
  24.                                                       /* Note 2 */
  25.      for ( i = 0; i < ROWS; i++ )
  26.           for ( j = 0; j < COLUMNS; j++ ) {
  27.                printf( "\tPosition %d,%d: ", i+1, j+1 );
  28.                scanf( "%f", &m[i][j] );               /* Note 3 */
  29.           }
  30.                                                       /* Note 4 */
  31.      determinant = m[0][0] * m[1][1] - m[0][1] * m[1][0];
  32.      printf( " The determinant is %8.2f\n", determinant );
  33.      return 0;
  34. }