Code:
#include<stdio.h>
#include<conio.h>
int main() {
int first_day, days_in_month;
int columns = 1;
int day_index = 1; // should be declared here - this is C, not C++
printf( "Enter day on which the 1st falls 1 = Sunday 2 = Monday etc : " );
scanf( "%d", &first_day );
printf( "How many days the month? : " );
scanf( "%d", &days_in_month );
printf( "\n SUN MON TUE WED THU FRI SAT\n" );
while(columns <= first_day -1) {
printf( " " );
columns += 1;
}
while(day_index <= days_in_month) {
if(columns == 7) // should be ==
{
printf( "%4d", day_index );
columns = 1;
printf( "\n" );
} else {
printf( "%4d", day_index ); // print this in a 4 width as well
columns += 1;
}
day_index += 1;
}
getch( );
}