diff options
-rw-r--r-- | 5p1.cpp | 1 | ||||
-rw-r--r-- | 6p1.cpp | 13 | ||||
-rw-r--r-- | 6p2.cpp | 35 | ||||
-rw-r--r-- | 6p3.cpp | 24 | ||||
-rw-r--r-- | 6p4.cpp | 26 | ||||
-rw-r--r-- | 6p5.cpp | 25 |
6 files changed, 123 insertions, 1 deletions
@@ -1,4 +1,3 @@ -#include <iostream> /* * @@ -0,0 +1,13 @@ + +/* + * + * 6.1 + * + * + */ + +int main () { + + // Arguments are initializers for functions parameters + return 0; +} @@ -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; +} @@ -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; +} @@ -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; +} @@ -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; +} |