I wrote code to do this calculation but I can't find it, so I'll leave implementation as "an exercise for the reader". Have fun!
Piece of cake considering I've already written this for my standard C library implementation. Here's the meat of it, slightly modified:
#include <stdio.h>
#define _LEAP_YEAR(year) (((year) > 0) && !((year) % 4) && (((year) % 100) || !((year) % 400)))
#define _LEAP_COUNT(year) ((((year) - 1) / 4) - (((year) - 1) / 100) + (((year) - 1) / 400))
const int yeardays[2][13] = {
{ -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 },
{ -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
};
const int monthdays[2][13] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
int weekday(int year, int month, int day)
{
int ydays, mdays, base_dow;
/* Correct out of range months by shifting them into range (in the same year) */
month = (month < 1) ? 1 : month;
month = (month > 12) ? 12 : month;
mdays = monthdays[_LEAP_YEAR(year)][month - 1];
/* Correct out of range days by shifting them into range (in the same month) */
day = (day < 1) ? 1 : day;
day = (day > mdays) ? mdays : day;
/* Find the number of days up to the requested date */
ydays = yeardays[_LEAP_YEAR(year)][month - 1] + day;
/* Find the day of the week for January 1st */
base_dow = (year * 365 + _LEAP_COUNT(year)) % 7;
return (base_dow + ydays) % 7;
}
Dates are tricky though, and this only works within the confines of ISO C library requirements.