Make totalDays a static. That way it is only initialized once. That means that you'll need a separate variable to hold the number of days for the current month. E.g.:
1 2 3 4
int numDays = totaldays[month];
if (month == 2 && leap) {
numDays++;
}
End a line with \n instead of endl. endl flushes the stream which really slows the program down. When I put a loop in main to run your code 100,000 times and send the output to /dev/null, the run time is:
real 0m22.305s
user 0m10.717s
sys 0m11.450s
Replacing endl the time changes to:
real 0m8.640s
user 0m8.533s
sys 0m0.000s
Move system("PAUSE") outside of printmonth(); (put it at the end of main() if you really need it)