From 80b6fffdf40a04ed7fa719b038ee4d5380dd3a87 Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 4 Sep 2024 19:56:28 +0200 Subject: more --- 5p1.cpp | 1 - 6p1.cpp | 13 +++++++++++++ 6p2.cpp | 35 +++++++++++++++++++++++++++++++++++ 6p3.cpp | 24 ++++++++++++++++++++++++ 6p4.cpp | 26 ++++++++++++++++++++++++++ 6p5.cpp | 25 +++++++++++++++++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 6p1.cpp create mode 100644 6p2.cpp create mode 100644 6p3.cpp create mode 100644 6p4.cpp create mode 100644 6p5.cpp diff --git a/5p1.cpp b/5p1.cpp index bc7c0ed..6babc13 100644 --- a/5p1.cpp +++ b/5p1.cpp @@ -1,4 +1,3 @@ -#include /* * 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 + +/* + * + * 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 + +/* + * + * 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 + +/* + * + * 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; +} -- cgit v1.2.3