Posted: . At: 3:52 AM. This was 13 years ago. Post ID: 1311
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

FizzBuzz solution in c. This should help someone out.

Here is a FizzBuzz solution I coded in C. This might help out some programming students if they are forced to write one of these programs and need help with it.

fizzbuzz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
 
int main(void) {
	int i;
	for (i = 0; i < 101; i++) {
		if (i % 3 == 0 && i % 5 == 0) {
			printf("FizzBuzz\n",);
		} else {
			if (i % 3 == 0) {
				printf("Fizz");
			} else {
				if (i % 5 == 0) {
					printf("Buzz\n");
				}
			}
			printf("%d\n", i);
		}
	}
	return 0;
}

This might look a bit ugly with the nested if statements, but if it works, it is fine.

A very nice FizzBuzz solution.FizzBuzz Solution in c
FizzBuzz Solution in c

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.