summaryrefslogtreecommitdiffstats
path: root/020.bc
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-14 20:19:53 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-14 20:19:53 -0500
commit691947f2d5a510420459f4cfa745891440cea346 (patch)
tree04ff3030990db4ed176cfce404f9afa304800fbf /020.bc
parent2fc6f19889b3a2d0a1d2c28706a488e6206983ae (diff)
downloadprojecteuler-691947f2d5a510420459f4cfa745891440cea346.tar.gz
projecteuler-691947f2d5a510420459f4cfa745891440cea346.zip
solution to problem 20
Diffstat (limited to '020.bc')
-rw-r--r--020.bc17
1 files changed, 17 insertions, 0 deletions
diff --git a/020.bc b/020.bc
new file mode 100644
index 0000000..d538cfe
--- /dev/null
+++ b/020.bc
@@ -0,0 +1,17 @@
+#!/usr/bin/bc
+
+scale = 0
+
+# from the bc man page
+define fact (x) {
+ if (x <= 1) return (1);
+ return (fact(x-1) * x);
+}
+
+total = 0
+num = fact(100)
+while (num > 0) {
+ total += num % 10
+ num = num / 10
+}
+total