C Program to print one month's calender in proper layout

Hi, this is the C code which I wrote to print one month’s calendar. This program takes care of the following situations or failure cases:

  1. It prints the dates as per the usual calendar layout
  2. It takes care of the situation where the month doesn’t start on Sunday.
  3. It takes care of the situation where the user may enter the number of days less than 28 or more than 31.
  4. It takes care of the situation where the user may enter the “start day” number less than 1 or more than 7.

The C code is given below


/*
C Program to print one month's calender in proper format
Programmed By:  www.123mylist.com 
*/
#include <stdio.h>
#include <conio.h>

int main()
{
    int i,days,start;
    do{
        printf("Enter the number of days\n");
        scanf("%d",&days);
    }while(days<28 | days>31);
    do{
                printf("\nEnter the start day number 1-Sun; 2-Mon; ... ; 7-SAT");
                scanf("%d",&start);
                    
    }while(start<0 | start>7);
    printf("\nSUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n");
    for(i=1;i<=days+start-1;i++)
    {
                              if(i<start)
                              {
                                       printf(" \t");
                              }
                              else
                              {
                                        printf("%d\t",i-start+1);
                              }
                              if((i%7)==0)
                              printf("\n");
    }
    
    
    getch();
    return 0;
}




Recommendations
Sign up for DigitalOcean Cloud

Get FREE $200 credits, deploy your hobby projects for Free

DigitalOcean Referral Badge
Sign up for Hostinger Cloud or VPS plans and get upto 20% Discount