/* --------------------------------------------------------------------- *
 * Filename: c004-1.c --- 
 * ---------------------------------------------------------------------- */
#include 
#include 

/* 行列の行と列の数 */
#define  CROWS     6
#define  CCOLS     8

int
main()
{
    int  i, j;
    double val[][CCOLS] = {
        { 0.3137, 0.2939, 0.6145, 0.2944, 0.7239, 0.8157, 0.0627, 0.3180 },
        { 0.3058, 0.1777, 0.8216, 0.7065, 0.9098, 0.9142, 0.1045, 0.7036 },
        { 0.5820, 0.3338, 0.5372, 0.2308, 0.3366, 0.6598, 0.5946, 0.3727 },
        { 0.1798, 0.1298, 0.8184, 0.9951, 0.0843, 0.2187, 0.5027, 0.8087 },
        { 0.7457, 0.9501, 0.0458, 0.4713, 0.2153, 0.5414, 0.4302, 0.0049 },
        { 0.4581, 0.0241, 0.7545, 0.7673, 0.6485, 0.6618, 0.5311, 0.4815 }
        };
    
    printf("%5.5s ", "i/j");
    for (j = 0; j < CCOLS; j++)
        printf("%8d ", j+1);
    putchar('\n');
    for (i = 0; i < CROWS; i++) {
        printf("%5d ", i+1);
        for (j = 0; j < CCOLS; j++)
            printf("%8.3f ", val[i][j]);
        putchar('\n');
    }
    return 0;
}
もう一つの方法
/* 行列の列の数, 行の数は、sizeof() で計算させるので、定数でなくてもよい*/
#define  CCOLS     8

int
main()
{
    int  i, j;
    double val[][CCOLS] = {
	{ 0.3137, 0.2939, 0.6145, 0.2944, 0.7239, 0.8157, 0.0627, 0.3180 },
	{ 0.3058, 0.1777, 0.8216, 0.7065, 0.9098, 0.9142, 0.1045, 0.7036 },
	{ 0.5820, 0.3338, 0.5372, 0.2308, 0.3366, 0.6598, 0.5946, 0.3727 },
	{ 0.1798, 0.1298, 0.8184, 0.9951, 0.0843, 0.2187, 0.5027, 0.8087 },
	{ 0.7457, 0.9501, 0.0458, 0.4713, 0.2153, 0.5414, 0.4302, 0.0049 },
	{ 0.4581, 0.0241, 0.7545, 0.7673, 0.6485, 0.6618, 0.5311, 0.4815 }
	};
    
    printf("%5.5s ", "i/j");
    for (j = 0; j < CCOLS; j++)
	printf("%8d ", j+1);
    putchar('\n');
    for (i = 0; i < sizeof(val)/sizeof(*val); i++) {
	printf("%5d ", i+1);
	for (j = 0; j < CCOLS; j++)
	    printf("%8.3f ", val[i][j]);
	putchar('\n');
    }
    return 0;
}

Copyright 2003 Ken Kishimoto