# include # include # include int main ( int argc, char *argv[] ); void test_a ( ); void timestamp ( ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: matrix_test() demonstrates the use of a doubly indexed matrix in C. Licensing: This code is distributed under the MIT license. Modified: 30 September 2024 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "arrays_test():\n" ); printf ( " C version\n" ); printf ( " Set up a matrix with 5 rows and 4 columns.\n" ); test_a ( ); /* Terminate. */ printf ( "\n" ); printf ( "arrays_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void test_a ( ) /******************************************************************************/ /* Purpose: test_a() demonstrates the use of a doubly indexed matrix in C. Licensing: This code is distributed under the MIT license. Modified: 30 September 2024 Author: John Burkardt */ { int a[5][4]; int i; int j; int k; printf ( "\n" ); printf ( "test_a():\n" ); printf ( " Use 'int a[5][4]' to create a doubly dimensioned array.\n" ); printf ( " Show how to assign values.\n" ); printf ( " Show we can use [i][j] double index to inspect values.\n" ); /* Use double indexing to set values. */ for ( j = 0; j < 4; j++ ) { for ( i = 0; i < 5; i++ ) { a[i][j] = 10 * ( i + 1 ) + ( j + 1 ); } } /* We can access values using two indices. */ printf ( "\n" ); printf ( " The matrix A[][]:\n" ); printf ( "\n" ); printf ( " i j k A[i][j]\n" ); printf ( "\n" ); k = 0; for ( i = 0; i < 5; i++ ) { for ( j = 0; j < 4; j++ ) { printf ( " %6d %6d %6d %6d\n", i, j, k, a[i][j] ); k = k + 1; } } return; } /********************************************************************/ void timestamp ( ) /********************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: May 31 2001 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 03 October 2003 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }