Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* "Fizzbuzz" variation: values are first stored in an array and only
- then printed to stdout, colored and with set width.*/
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char words[101][9];
- char coloring[101][13];
- int i;
- for(i = 1; i <= 100; i++){
- if(i % 15 == 0) {
- strcpy(words[i], "fizzbuzz");
- strcpy(coloring[i], "\033[31;1m");
- }
- else if(i % 5 == 0) {
- strcpy(words[i], "buzz");
- strcpy(coloring[i], "\033[32;1m");
- }
- else if(i % 3 == 0) {
- strcpy(words[i], "fizz");
- strcpy(coloring[i], "\033[34;1m");
- }
- else {
- (void)snprintf(words[i], 3, "%d", i);
- strcpy(coloring[i], "\033[36;1m");
- }
- }
- char sep[] = " \t";
- for(i = 1; i <= 100; i++) {
- printf("%s%2d\033[0m: %s%s", coloring[i], i, words[i], sep);
- if(i % 10 == 0) {
- (void)putchar('\n');
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement