commit 21f2358da84fbad13dfd8e3696dabb7ed8f73669
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sun, 10 Nov 2024 06:57:08 -0800
Initial commit
Initialize with functional CracklePop program, README, and Makefile.
Diffstat:
A | Makefile | | | 23 | +++++++++++++++++++++++ |
A | README | | | 7 | +++++++ |
A | main.c | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,23 @@
+NAME = cracklepop
+SRC = main.c
+OBJ = ${SRC:.c=.o}
+
+CC = cc
+CFLAGS = -std=c99 -Wall
+LDFLAGS =
+
+all: ${NAME}
+
+${NAME}: ${OBJ}
+ ${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+${NAME}: Makefile
+
+clean:
+ rm -f ${NAME} ${OBJ}
+
+.c.o:
+ ${CC} ${CFLAGS} -c -o $@ $<
+
+.PHONY: all clean
+.SUFFIXES: .c .o
diff --git a/README b/README
@@ -0,0 +1,7 @@
+CraclePop implementation in C for the Recurse Center
+<https://www.recurse.com/> application:
+
+ Write a program that prints out the numbers 1 to 100 (inclusive).
+ If the number is divisible by 3, print Crackle instead of the number.
+ If it's divisible by 5, print Pop. If it's divisible by both 3 and
+ 5, print CracklePop. You can use any language.
diff --git a/main.c b/main.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+int
+cracklepop(unsigned int n)
+{
+ int cp;
+
+ cp = 0;
+ if (n % 3 == 0) {
+ if (printf("Crackle") < 0)
+ return 1;
+ cp = 1;
+ }
+
+ if (n % 5 == 0) {
+ if (printf("Pop") < 0)
+ return 1;
+ cp = 1;
+ }
+
+ if (cp) {
+ return printf("\n") < 0;
+ }
+
+ return printf("%d\n", n) < 0;
+}
+
+int
+main(void)
+{
+ unsigned int i;
+
+ for (i = 1; i <= 100; ++i) {
+ if (cracklepop(i)) {
+ perror("cracklepop");
+ return 1;
+ }
+ }
+
+ return 0;
+}