/* --------------------------------------------------------------------- // Figure 8.5: Computing N factorial. // --------------------------------------------------------------------- */ #include void main( void ) { int N; /* Loop counter. */ short int facts = 1; /* We compute factorial using 5 types. */ short unsigned factu = 1; /* 0! is defined to be 1. */ long int factl = 1; float factf = 1.0; double factd = 1.0; puts( "\n N N factorial \n" " short unsigned \n" " int short int long int \t float \t\t\t double \n" ); /* Compute N! using each type, quit after 40 factorial. ------------ */ for (N = 1; N <= 40; ++N) { facts *= N; factu *= N; factl *= N; factf *= N; factd *= N; if (N <= 9) printf( "%3i %7hi %7u ", N, facts, factu ); else printf( "%3i ", N ); if (N <= 17) printf( "%12li", factl ); else printf( " " ); printf( " %18.12g %23.22g\n", factf, factd ); } }