//p41.c --- - ¥Î¤F¥ß©e¤uµ{Âà¥]·§©À: ¥t¼gfunction°µ¿é¤J ! // In this version, we write a ¥iŪ¤Jlong¾ã¼Æªº¨ç¼Æ(function) long getLong( ); // µM«á¨C¦¸­nŪ¨ú¤@­Ó¾ã¼Æ´N ¡§¥s¡¨ (Call) ¥¦À°¦£°µ ! #include #include long n; // (ª`·N) atol( ), atoi( ), ¥H¤Î atof( ) ³£«Å§i¦b long getLong(void); // ¥ý«Å§i(Án©ú)·|¼g¤@­Ó getLong( ) function ƒº void pascal(int); // Án©ú·|¼g¤@­Ó¥i±µ¨ü¤@­Ó int °Ñ¼Æªºfunction ¥s°µ pascal int main( ) { // ¤j¦h¼Æ main program ³£³o¼Ë¶}ÀY while(49==49) { // (ª`·N) ¥i¥H§ï¥Î§Oªº¤èªk°µ Loop printf("Pascal Triangle of order n, Give me n: "); n = getLong( ); // ¼g¦¨¨ç¼Æ (function; ¨ç¦¡) ¬O­Ó«Ü¦nªº²ßºD if( n < 0 ) break; // ­Y¬O­t¼Æ´N°± ! (ª`·N) ¥i¥H§ï¥Î§Oªº¤èªk pascal( (int)n ); // (cast) ¦]¬° n ¬O long, ¥i¬O¸Ó pascal ­n±µ¨ü int // (ª`·N) ¥i¥H°Ý user ­n¤£­nÄ~Äò? } // while printf("Bye bye!\nHit RETURN key ..."); getchar( ); // ¥ø¹ÏŪ¨ú¤@­Ó char, Åýµ{¦¡°±µÛµ¥ User «ö RETURN Áä return 0; // §iª¾§@·~¨t²Î(OS)ªí¥Ü§Ú­Ì³o¥Dµ{¦¡¥¿±`µ²§ô }// main( long getLong( ) { // ¥H«á­n§ï¿é¤Jªº¤èªk¥u­n§ï³o function ´N¥i :-) static char buf[99]; // a string buffer for input; why "static" ? double ans; fgets(buf, sizeof(buf), stdin); // stdin ´N¬OÁä½L, ­n°O±o§t¤J ans = atol(buf); // ±q¦r¦ê¤¤Åª¥X long ¾ã¼Æ (long) ////// ­Y¬O¹ê¼Æ´N§â atol §ï¬° atof ³o¤]¬O§O¤H¼g¦nªº¨ç¼Æ(¨ç¦¡) return ans; } void pascal(int n) { int i, k; // for Loop static int x[38][38]; // for Pascal Triangle; ª½±µ¼g 38 ¤£¤Ó¦n! ¥Î #define for(i = 0; i <= n; ++i) { //.. ¥ý§â¤E¤E­¼ªkªíªºµ{¦¡¬ã¨s²M·¡¹ï¦¹ÃD·|²¤¦³À°§U ƒº } // for(i }// pascal // Ãö©ó Pascal Triangle µ{¦¡, ½Ð°Ñ¦Ò¥»½Òµ{µ¹ªº§ë¼v¤ù¤º»¡©ú! // ÁÙ¤£·|ªº¥ý½m²ß¦L¥X©Ò¦³ 1 ¨ì n ªº©_¼Æ (Hint: k%2 !=0 «h k ´N¬O©_¼Æ) // ¦pªG§A¦³ K&R ½Ò¥», ¥i¬ã¨s½Ò¥»¤º°Q½× atoi »P atof ¨ç¼Æ¬O¦p¦ó¼gªº, // ¥i¥HÅý§A¼W¥[¥\¤O³á !