したがって、ユーザーは年を入力し、うるう年かどうかを示します。しかし、うるう年のときに曜日をポップアップ表示するためのサポートが必要です。
# include <math.h>
# include <stdio.h>
int main (void)
{
int yearEntered;
printf("Enter a year: ");
int read = scanf("%d", &yearEntered);
if (read == 0 )
{
printf("Bad input: requires an integer");
}
else if (yearEntered%4==0 && yearEntered%100!=0 || yearEntered%400==0)
{
printf("%04d is a leap year and February 29th is on a \n",yearEntered, dayString);
// Not so sure about this switch statement......
switch (DayOfWeek)
{
case 0:
{
dayString("Sunday");
break;
}
case 1:
{
dayString("Monday");
break;
}
case 2:
{
dayString("Tuesday");
break;
}
case 3:
{
dayString("Wednesday");
break;
}
case 4:
{
dayString("Thursday");
break;
}
case 5:
{
dayString("Friday");
break;
}
case 6:
{
dayString("Saturday");
break;
}
default:
{
dayString("");
}
}
else if (yearEntered < 1752)
{
printf("%04d is not a 4 digit year after 1752.",yearEntered);
}
else
{
printf("%d is not a leap year.\n",yearEntered);
}
return 0;
}