I am trying to create the calendar program in Erlang , but I was not able to complete the logic of the code. And I tried the same calendar program in C language and its working but not accurate (i.e in the terms of days printing a/c to the Month and Year).
Tried Code :
#include<stdio.h>
int main()
{
int year;
int month, day,i;
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
" January",
" February",
" March",
" April",
" May",
" June",
" July",
" August",
" September",
" October",
" November",
" December" };
printf("Please enter a year: ");
scanf(" %d", &year);
if(((year%4==0) && (year%100!=0)) || (year%400==0))
{
days_in_month[2] = 29;
}
else
{
days_in_month[2] = 28;
}
for(i= 1; i<=12; i++)
{
printf("%s", months[i]);
printf(" Sun Mon Tue Wed Thu Fri Sat\n" );
for ( day = 1; day <= 1; day++ )
{
printf(" ");
}
for ( day = 1; day <= days_in_month[i]; day++ )
{
(!(day % 7))?printf("%2d", day ):printf("%2d", day);
if ( ( day ) % 7 > 0 ){
printf(" " );
}
else{
printf("\n " );
}
}
printf("\n " );
}
return 0;
}
And the Example Output for the year (2020) and for one month:
December
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31