This program is supposed to determine the day of the week for 2015. Could someone tell me how I could shorten my code?
#include <stdio.h>
#include <conio.h>
void findDay(int , int);
int main(void)
{
int jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec;
for(jan=1; jan<=31; ++jan)
{
printf(" 01/%d/2015 is", jan);
findDay(jan, 0);
}
for(feb=1; feb<=28; ++feb)
{
printf("02/%d/2015 is", feb);
findDay(feb, 3);
}
for(mar=1; mar<=31; ++mar)
{
printf("03/%d/2015 is", mar);
findDay(mar, 3);
}
for(apr=1; apr<=30; ++apr)
{
printf("04/%d/2015 is", apr);
findDay(apr, 6);
}
for(may=1; may<=31; ++may)
{
printf("05/%d/2015 is", may);
findDay(may, 1);
}
for(jun=1; jun<=30; ++jun)
{
printf("06/%d/2015 is", jun);
findDay(jun, 4);
}
for(jul=1; jul<=31; ++jul)
{
printf("07/%d/2015 is", jul);
findDay(jul, 6);
}
for(aug=1; aug<=31; ++aug)
{
printf("08/%d/2015 is", aug);
findDay(aug, 2);
}
for(sep=1; sep<=30; ++sep)
{
printf("09/%d/2015 is", sep);
findDay(sep, 5);
}
for(oct=1; oct<=31; ++oct)
{
printf("10/%d/2015 is", oct);
findDay(oct, 0);
}
for(nov=1; nov<=30; ++nov)
{
printf("11/%d/2015 is", nov);
findDay(nov, 3);
}
for(dec=1; dec<=31; ++dec)
{
printf("12/%d/2015 is", dec);
findDay(dec, 5);
}
getch();
return 0;
}
void findDay(int dow, int num)
{
int x;
x=(6+15+3+dow+num)%7;//a formula to calculate the day of the week
switch (x)
{
case 0:
printf(" Sunday\n");
break;
case 1:
printf(" Monday\n");
break;
case 2:
printf(" Tuesday\n");
break;
case 3:
printf(" Wednesday\n");
break;
case 4:
printf(" Thursday\n");
break;
case 5:
printf(" Friday\n");
break;
case 6:
printf(" Saturday\n");
break;
default:
printf("Invalid Input");
}
}