An acquaintant posted on IRC a link to Jeff Atwood’s Coding Horror blog and his post entitled “Why Can’t Programmers.. Program?“.

The task should be straightforward:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Here’s my solution to the FizzBuzz problem, written in C (ISO/IEC 9899:1999, C99):

#include <stdio.h>

int main(void)
{
  int i, f, b;

  for (i = 1; i <= 100; i++) {
    f = i % 3;
    b = i % 5;

    if (f == 0 || b == 0) {
      if (f == 0) {
        fputs("Fizz", stdout);
      }

      if (b == 0) {
        fputs("Buzz", stdout);
      }
    }
    else {
      printf("%d", i);
    }

    puts("");
  }

  return 0;
} // main()

// fizzbuzz.c

It didn’t take me more than a few minutes to type, compile, and run this little toy program. I guess it all boils down to knowledge (math usually comes in handy), experience, and the ability to analyse what the task is really about.

Is it true that CS graduates nowadays are unable to produce something similar to the code above, be it verbally, written on paper, or typed on a computer?