Lesson 6 fizzbuzz

This commit is contained in:
deck committed 2026-10-06 21:14:55 +02:00
1 parent 93bcca369a
commit 8fc7170ccd
1 file changed
+19 -7
+19 -7
View File
@@ -1,13 +1,25 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
int main(void) { int main(void) {
char buf[100] = ""; int n;
fgets(buf, sizeof buf, stdin); scanf("%d", &n);
int resultof3 = n%3;
for (int i=0; !(buf[i] == '\0'); i++) { int resultof5 = n%5;
if (buf[i] == '\n') {buf[i] = '\0';} if (!resultof5 && !resultof3) {
printf("FizzBuzz");
} else if (!resultof3) {
printf("Fizz");
} else if (!resultof5) {
printf("Buzz");
} else {
printf("%d", n);
} }
printf("%d\n", (int)strlen(buf)); /* TODO: print exactly one line:
multiple of 3 and 5 -> FizzBuzz
multiple of 3 only -> Fizz
multiple of 5 only -> Buzz
anything else -> the number itself */
return 0; return 0;
} }