#include <stdio.h>

int main() {

  // User Entries
  int days_in_month = 0;
  int starting_day = 0;

  // Loop Control Variable
  // int i;
  int day_i = 0;

  // Ask the user for the number of days in the month and
  // the start day of the week for the calendar month desired.
  printf( "Enter number of days in month:  " );
  scanf( "%d", &days_in_month );

  printf("Enter starting day of the week (1=Sun, 7=Sat):  ");
  scanf( "%d", &starting_day );

  // Display Calendar Heading
  printf( "  S  M  T  W  R  F  S\n" );

  // Padding before start day of the week for given month
  // for ( i = 1; i < starting_day; i++ ) {
  for ( day_i = 1; day_i < starting_day; day_i++ ) {
    printf("   ");
  }

  // DISPLAY CALENDAR
  // for ( i = 1; i <= days_in_month; i++ ) {
  for ( day_i = 1; day_i <= days_in_month; day_i++ ) {
    printf( "%3d", day_i );

    if ( ( day_i + starting_day - 1 ) % 7  == 0 ) {
      printf("\n");
    }
  }

  printf("\n");
  return 0;
}
