diff options
author | Oskar <[email protected]> | 2024-09-05 11:18:52 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-05 11:18:52 +0200 |
commit | d2f183b8d0008bdb29e6c5c4fa04c14d7525ca9b (patch) | |
tree | d1ab4ddc3cea4214ffdb8f574a85283545b372f8 | |
parent | a30d605024322ada2206d10898b8dfd6220107c1 (diff) |
more
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | 6p4.cpp | 4 | ||||
-rw-r--r-- | Chapter6.hpp | 12 | ||||
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | fact.cc | 20 | ||||
-rw-r--r-- | factMain.cc | 7 |
6 files changed, 60 insertions, 3 deletions
@@ -2,3 +2,5 @@ bin/ redirection/ TODO gede.ini +*.o +*.obj @@ -7,7 +7,7 @@ * */ -uint64_t fact(void) { +uint64_t fact_i(void) { uint64_t val; if(std::cin >> val) {} else { return 0; } @@ -21,6 +21,6 @@ uint64_t fact(void) { int main () { - std::cout << fact() << std::endl; + std::cout << fact_i() << std::endl; return 0; } diff --git a/Chapter6.hpp b/Chapter6.hpp new file mode 100644 index 0000000..b3e431b --- /dev/null +++ b/Chapter6.hpp @@ -0,0 +1,12 @@ +#include <iostream> + +/* + * + * 6.8 + * + * + */ + +int fact(int val); +uint64_t fact_i(void); +int AbsoluteValue(int v); @@ -8,7 +8,7 @@ OBJS_CLANG=$(patsubst %.cpp, $(BINDIR)/clang/%, $(SRCS)) OBJS_GCC=$(patsubst %.cpp, $(BINDIR)/gcc/%, $(SRCS)) MAKEFLAGS += -j$(nproc) -all: clang gcc +all: clang gcc ch6e9 clean: rm -rf $(BINDIR)/gcc/* @@ -26,4 +26,20 @@ $(BINDIR)/gcc/%: %.cpp @mkdir -p $(BINDIR)/gcc $(CC2) $(CFLAGS_GCC) -o $@ $< +ch6e9: $(BINDIR)/clang/FACT $(BINDIR)/gcc/FACT + +$(BINDIR)/clang/FACT: fact.o factMain.o + @mkdir -p $(BINDIR)/clang + $(CC1) $(CFLAGS_CLANG) factMain.o fact.o -o $(BINDIR)/clang/FACT + +$(BINDIR)/gcc/FACT: fact.o factMain.o + @mkdir -p $(BINDIR)/gcc + $(CC2) $(CFLAGS_GCC) factMain.o fact.o -o $(BINDIR)/gcc/FACT + +fact.o: fact.cc + $(CC2) $(CFLAGS_GCC) -c fact.cc + +factMain.o: factMain.cc + $(CC2) $(CFLAGS_GCC) -c factMain.cc + .PHONY: all clean clang gcc @@ -0,0 +1,20 @@ +#include <iostream> + +/* + * + * + * + * + */ + +uint64_t fact_i(void) { + + uint64_t val; + if(std::cin >> val) {} else { return 0; } + uint64_t ret = 1; + while(val > 1) { + ret *= val--; + } + + return ret; +} diff --git a/factMain.cc b/factMain.cc new file mode 100644 index 0000000..58ae446 --- /dev/null +++ b/factMain.cc @@ -0,0 +1,7 @@ +#include "Chapter6.hpp" + +int main () { + + std::cout << fact_i() << std::endl; + return 0; +} |