소스 검색

[C] Adding solution for problem 0002

Vinicius Teshima 1 년 전
부모
커밋
df700006ab
4개의 변경된 파일40개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 1
      c/.gitignore
  2. 24 0
      c/0002.c
  3. 8 3
      c/Makefile
  4. 6 0
      c/Project.ede

+ 2 - 1
c/.gitignore

@@ -2,4 +2,5 @@
 *.o
 
 # Executables
-0001
+0001
+0002

+ 24 - 0
c/0002.c

@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int
+main(int argc, const char **argv)
+{
+	uint64_t sum = 2;
+	uint64_t t = 0;
+	uint64_t fib = 2;
+	uint64_t fib_old = 1;
+	uint64_t upper_limit = 4000000;
+
+	while ( fib < upper_limit ) {
+		t = fib_old;
+		fib_old = fib;
+		fib += t;
+		sum += ( fib < upper_limit ) * (( (fib & 1) == 0 ) * fib);
+	}
+
+	printf("Result = %ld!\n", sum);
+	(void) argc; (void) argv;
+	return 0;
+}
+

+ 8 - 3
c/Makefile

@@ -17,13 +17,15 @@ CC=gcc
 C_COMPILE=$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
 C_DEPENDENCIES=-Wp,-MD,.deps/$(*F).P
 C_LINK=$(CC) $(CFLAGS) $(LDFLAGS) -L.
+0002_SOURCES=0002.c
+0002_OBJ= 0002.o
 VERSION=1.0
 DISTDIR=$(top)ProjectEuler_C-$(VERSION)
 top_builddir = 
 
-DEP_FILES=.deps/0001.P
+DEP_FILES=.deps/0001.P .deps/0002.P
 
-all: 0001
+all: 0001 0002
 
 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
 -include $(DEP_FILES)
@@ -35,6 +37,9 @@ DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
 0001: $(0001_OBJ)
 	$(C_LINK) -o $@ $^ $(LDDEPS)
 
+0002: $(0002_OBJ)
+	$(C_LINK) -o $@ $^ $(LDDEPS)
+
 tags: 
 
 
@@ -45,7 +50,7 @@ clean:
 
 dist:
 	mkdir $(DISTDIR)
-	cp $(0001_SOURCES) $(ede_FILES) $(DISTDIR)
+	cp $(0001_SOURCES) $(0002_SOURCES) $(ede_FILES) $(DISTDIR)
 
 Makefile: Project.ede
 	@echo Makefile is out of date!  It needs to be regenerated by EDE.

+ 6 - 0
c/Project.ede

@@ -10,6 +10,12 @@
       :name "0001"
       :path ""
       :source '("0001.c")
+      :configuration-variables '("debug" ("CFLAGS" . "-g") ("LDFLAGS" . "-g")))
+    (ede-proj-target-makefile-program "0002"
+      :object-name "0002"
+      :name "0002"
+      :path ""
+      :source '("0002.c")
       :configuration-variables '("debug" ("CFLAGS" . "-g") ("LDFLAGS" . "-g"))))
   :configurations '("debug" "release")
   :object-name "ProjectEuler_C"