From d2f183b8d0008bdb29e6c5c4fa04c14d7525ca9b Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 5 Sep 2024 11:18:52 +0200 Subject: more --- .gitignore | 2 ++ 6p4.cpp | 4 ++-- Chapter6.hpp | 12 ++++++++++++ Makefile | 18 +++++++++++++++++- fact.cc | 20 ++++++++++++++++++++ factMain.cc | 7 +++++++ 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Chapter6.hpp create mode 100644 fact.cc create mode 100644 factMain.cc diff --git a/.gitignore b/.gitignore index c175108..3b5110b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ bin/ redirection/ TODO gede.ini +*.o +*.obj diff --git a/6p4.cpp b/6p4.cpp index 28c6fa5..441d423 100644 --- a/6p4.cpp +++ b/6p4.cpp @@ -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 + +/* + * + * 6.8 + * + * + */ + +int fact(int val); +uint64_t fact_i(void); +int AbsoluteValue(int v); diff --git a/Makefile b/Makefile index 4648bd7..259e0a6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/fact.cc b/fact.cc new file mode 100644 index 0000000..a79d2b7 --- /dev/null +++ b/fact.cc @@ -0,0 +1,20 @@ +#include + +/* + * + * + * + * + */ + +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; +} -- cgit v1.2.3