Pages

13 May 2013

we're all cranks-in-waiting

So I read this article, linked to on this Slashdot article which prompted me to post this on my G+ account.

Easy to Crank

Earlier this morning it occurred to me that I was behaving in the manner of a crank. I was acting as if my inexpert opinion counted as much as the opinions of those who've studied and practiced computer programming much of, if not most, of their careers.

Additionally, it doesn't seem to take much to turn one into a crank.

Aside:

I still can't stop futzing with the code.



#include <stdio.h>

int fizz_buzz(int num)
{
        int m1 = 3, m2 = 5, f = 0;

        if (num % m1 == 0) {
                f = 1;
        }

        if (num % m2 == 0) {
                f = f + 2;
        }

        return(f);
}

int main() 
{
        int max = 100, n = 1;
        char s1[] = "fizz", s2[] = "buzz";

        while (n <= max) {
                switch (fizz_buzz(n)) {
                        case 1:
                                printf("%s", s1);
                                break;
                        case 2:
                                printf("%s", s2);
                                break;
                        case 3:
                                printf("%s%s", s1, s2);
                                break;
                        default:
                                printf("%d", n);
                                break;
                }
                
                printf("\n");
                n++;
        }
        return 0;
}

No comments:

Post a Comment