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-2.awk 3 # version 0.2 of fac1.awk 4 # 5 6 function factorial(n, i) 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 | [robert@saphires awk_var]$ echo "" | awk -f fac1-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 |
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-3.awk 3 # version 0.3 of fac1.awk 4 # 5 6 function factorial(n, _ARGVEND_, i) 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 | [robert@saphires awk_var]$ echo "" | awk -f fac1-3.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 |