summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--5p1.cpp1
-rw-r--r--6p1.cpp13
-rw-r--r--6p2.cpp35
-rw-r--r--6p3.cpp24
-rw-r--r--6p4.cpp26
-rw-r--r--6p5.cpp25
6 files changed, 123 insertions, 1 deletions
diff --git a/5p1.cpp b/5p1.cpp
index bc7c0ed..6babc13 100644
--- a/5p1.cpp
+++ b/5p1.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
/*
*
diff --git a/6p1.cpp b/6p1.cpp
new file mode 100644
index 0000000..0f4348e
--- /dev/null
+++ b/6p1.cpp
@@ -0,0 +1,13 @@
+
+/*
+ *
+ * 6.1
+ *
+ *
+ */
+
+int main () {
+
+ // Arguments are initializers for functions parameters
+ return 0;
+}
diff --git a/6p2.cpp b/6p2.cpp
new file mode 100644
index 0000000..1791977
--- /dev/null
+++ b/6p2.cpp
@@ -0,0 +1,35 @@
+
+/*
+ *
+ * 6.2
+ *
+ *
+ */
+
+int main () {
+
+ /* Corrected versions
+
+ (a)
+ string f() {
+ string s;
+ // . . .
+ return s;
+ }
+
+ (b)
+ void f2(int i) { }
+
+ (c)
+ int calc(int v1, int v2) {
+
+ return v1 + v2;
+ }
+
+ (d)
+ double square(double x) {
+ return x * x;
+ }
+ */
+ return 0;
+}
diff --git a/6p3.cpp b/6p3.cpp
new file mode 100644
index 0000000..b653289
--- /dev/null
+++ b/6p3.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+
+/*
+ *
+ * 6.3
+ *
+ *
+ */
+
+int fact(int val) {
+
+ int ret = 1;
+ while(val > 1) {
+ ret *= val--;
+ }
+
+ return ret;
+}
+
+int main () {
+
+ std::cout << fact(5) << std::endl;
+ return 0;
+}
diff --git a/6p4.cpp b/6p4.cpp
new file mode 100644
index 0000000..28c6fa5
--- /dev/null
+++ b/6p4.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+
+/*
+ *
+ * 6.4
+ *
+ *
+ */
+
+uint64_t fact(void) {
+
+ uint64_t val;
+ if(std::cin >> val) {} else { return 0; }
+ uint64_t ret = 1;
+ while(val > 1) {
+ ret *= val--;
+ }
+
+ return ret;
+}
+
+int main () {
+
+ std::cout << fact() << std::endl;
+ return 0;
+}
diff --git a/6p5.cpp b/6p5.cpp
new file mode 100644
index 0000000..bcdec06
--- /dev/null
+++ b/6p5.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+
+/*
+ *
+ * 6.5
+ *
+ *
+ */
+
+int AbsoluteValue(int v) {
+
+ if (v < 0) {
+ return -v;
+ }
+
+ return v;
+}
+
+int main () {
+
+ int v;
+ if(std::cin >> v) {} else { return -1; }
+ std::cout << AbsoluteValue(v) << std::endl;
+ return 0;
+}