1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | [robert@saphires awk_var]$ echo "" | awk -f fac1-3.awk --dump-variables=/tmp/var.dump fac(1) = 1 fac(2) = 2 fac(3) = 6 fac(4) = 24 fac(5) = 120 fac(6) = 720 fac(7) = 5040 fac(8) = 40320 fac(9) = 362880 fac(10) = 3628800 [robert@saphires awk_var]$ cat /tmp/var.dump ARGC: number (1) ARGIND: number (0) ARGV: array, 1 elements BINMODE: number (0) CONVFMT: string ("%.6g") ERRNO: number (0) FIELDWIDTHS: string ("") FILENAME: string ("-") FNR: number (1) FS: string (" ") IGNORECASE: number (0) LINT: number (0) NF: number (0) NR: number (1) OFMT: string ("%.6g") OFS: string (" ") ORS: string ("\n") RLENGTH: number (0) RS: string ("\n") RSTART: number (0) RT: string ("") SUBSEP: string ("\034") TEXTDOMAIN: string ("messages") i: number (11) s: number (3628800) value: number (3628800) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 1 # 2 # fac1-4.awk 3 # version 0.4 of fac1.awk 4 # 5 6 function factorial(n, _ARGVEND_, i, s) 7 { 8 s=1; 9 10 for (i=1; i<=n; i++) 11 { 12 s *= i; 13 } 14 15 return s; 16 } 17 18 { 19 for (i=1; i<=10; i++) 20 { 21 value = factorial(i); 22 printf("fac(%d) = %d\n", i, value); 23 } 24 } 25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [robert@saphires awk_var]$ echo "" | awk -f fac1-4.awk --dump-variables=/tmp/var.dump fac(1) = 1 fac(2) = 2 fac(3) = 6 fac(4) = 24 fac(5) = 120 fac(6) = 720 fac(7) = 5040 fac(8) = 40320 fac(9) = 362880 fac(10) = 3628800 [robert@saphires awk_var]$ cat /tmp/var.dump ......(omitted) i: number (11) value: number (3628800) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1 # 2 # library for awk 3 # 4 5 function factorial(n, _ARGVEND_, i, s) 6 { 7 s=1; 8 9 for (i=1; i<=n; i++) 10 { 11 s *= i; 12 } 13 14 return s; 15 } 16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 # 2 # fac3.awk 3 # original version of fac3.awk 4 # 5 6 { 7 for (i=1; i<=10; i++) 8 { 9 value = factorial(i); 10 printf("fac(%d) = %d\n", i, value); 11 } 12 } 13 |
1 2 3 4 5 6 7 8 9 10 11 | [robert@saphires awk_var]$ echo "" | awk -f fac-lib.awk -f fac3.awk fac(1) = 1 fac(2) = 2 fac(3) = 6 fac(4) = 24 fac(5) = 120 fac(6) = 720 fac(7) = 5040 fac(8) = 40320 fac(9) = 362880 fac(10) = 3628800 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 1 # 2 # fac3-2.awk 3 # original version of fac3-2.awk 4 # 5 6 @include fac-lib.awk 7 8 { 9 for (i=1; i<=10; i++) 10 { 11 value = factorial(i); 12 printf("fac(%d) = %d\n", i, value); 13 } 14 } 15 |
1 2 3 4 5 6 7 8 9 10 11 | [robert@saphires awk_var]$ echo "" | igawk -f fac3-2.awk fac(1) = 1 fac(2) = 2 fac(3) = 6 fac(4) = 24 fac(5) = 120 fac(6) = 720 fac(7) = 5040 fac(8) = 40320 fac(9) = 362880 fac(10) = 3628800 |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |