Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 5 June 2016

PROBLEM 21:

Mr. Bhola is fed-up of giving individual dates as inputs. He wants a complete calendar starting from 1st January to 31st December for a given year.

Write a C program that takes input as a int in format yyyy.

CODE:

#include<stdio.h>
#define TRUE 1
#define FALSE 0
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
    " ",
    "\n\n\nJanuary",
    "\n\n\nFebruary",
    "\n\n\nMarch",
    "\n\n\nApril",
    "\n\n\nMay",
    "\n\n\nJune",
    "\n\n\nJuly",
    "\n\n\nAugust",
    "\n\n\nSeptember",
    "\n\n\nOctober",
    "\n\n\nNovember",
    "\n\n\nDecember",
};
    int inputyear()

    {
        int year;
        printf("Enter any year:\n");
        scanf("%d",&year);
        return year;
    }

    int determinedaycode(int year)
    {
        int daycode;
        int d1,d2,d3;

        d1=(year-1.)/4.0;
        d2=(year-1.)/100.;
        d3=(year-1.)/400.;
        daycode = (year + d1-d2+d3)%7;
        return daycode;
    }
    int determineleapyear(int year)
    {
        if(year%4==FALSE && year%100!=FALSE|| year%100==FALSE)
        {
            days_in_month[2]=29;
            return TRUE;
        }
        else
        {
            days_in_month[2]=28;
            return FALSE;
        }
    }
    void calender(int year,int daycode)
    {
        int month,day;
        for(month=1;month<=12;month++)
        {
            printf("%c",months[month]);
            printf("\n\nSun  Mon  Tues  Wed  Thurs  Fri  Sat\n");
            for(day=1;day<=1+daycode * 5;day++)
            {
                printf(" ");
            }
            for(day=1;day<=days_in_month[month];day++)
            {
                printf("%2d",day);
                if((day + daycode)%7>0)
                printf("  " );
                else
                printf("\n " );
            }
            daycode=(daycode+daycode+days_in_month[month])%7;
        }
    }
    int main()
    {
        int year,daycode,leapyear;

        year=inputyear();
        daycode=determinedaycode(year);
        determineleapyear(year);
        calender(year,daycode);
        printf("\n");
return 0;
    }

Program Output:












For more problems click here


No comments:

Post a Comment