try another color scheme:


Go Back   TECH6.0 > Get Techie > Programming > C/C++/VC++


Calendar of any Year

This is a discussion on Calendar of any Year within the C/C++/VC++ section, part of the Programming category; Shows calendar of any year.. Code: #include<stdio.h> #include<conio.h> int year,month; void display(int); void main() { do { int ch; void ...

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 14-03-2008, 08:19 PM
webwizzy's Avatar

Administrator
 
Name: Vinayak
Join Date: Feb 2008
Location: India
Phone: Samsung Wave
Posts: 1,116
webwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nice
Send a message via Yahoo to webwizzy
Default Calendar of any Year

Shows calendar of any year..

Code:
#include<stdio.h>
#include<conio.h>

int year,month;
void display(int);
void main()
{
    do
    {
        int ch;
        void calc();
        clrscr();
        printf("\n1.View Year");
        printf("\n2.View Month");
        printf("\nEnter choice::");
        scanf("%d",&ch);
        switch(ch)
        {
         case 1:
            printf("Enter The Year:");
            scanf("%d",&year);
            clrscr();
            for(month=1;month<=12;month++)
            {
                calc();
                if(month%3==0)
                {
                    printf("\nPress any key to continue:");
                    printf("\n\n");
                    getch();
                }
            }
            break;
         case 2:
            printf("Enter The Year:");
            scanf("%d",&year);
            printf("Enter The Month:");
            scanf("%d",&month);
            calc();
            break;
         default:       printf("enter right choice..try again");
                continue;
         }
         printf("\nPress n to exit or any other key to exit");
      }while(getch()!='n');

}


void calc()
{
    int i,j,day,flag=0;
    register int index=1;
    if(year>2006)
    for(i=2006;i<year;i++)
    {
        if(isleap(i))
        {
            index=index+1;

        }
        index=index+1;
        if(index>7)
        index=index-7;
    }
    else
    {       flag=1;
        for(i=2006;i>year;i--)
        {
            if(isleap(i-1))
            {
                index=index-1;

            }
            index=index-1;
            if(index<=0)
            index=7+index;
        }
    }

    for(j=1;j<month;j++)
    {
        day=checkmonth(j,year);
        //if(flag==1)
            //index=index-(day%7);
           //    else
            index=index+(day%7);

        if(index>7)
            index=index-7;
        //if(index<=0)
               //    index=7+index;
    }
    display(index);

}

int isleap(int i)
{
    if(i%400==0 || (i%4==0 && i%100))
    return 1;
    else
    return 0;
}

int checkmonth(int j,int y)
{               int day;
        if(j==4 || j==6 || j==9 || j==11)
        day=30;
        else if(j==2 && isleap(y))
        day=29;
        else if(j==2)
        day=28;
        else
        day=31;
        return day;
}

void display(int index)
{
    int arr[6][7],day,row,col,i,j;
    char mon[12][20]={"january","february","march","april","may","june","july","august","september","october","november","december"};
    day=checkmonth(month,year);
    row=0;
    col=index-1;
    printf("\n\n\n\t\t\t\t\t%s\n\n",mon[(month-1)]);
    for(i=0;i<6;i++)
    {
        for(j=0;j<7;j++)
        arr[i][j]=0;
    }
    for(i=1;i<=day;i++)
    {
        arr[row][col]=i;
        col++;
        if(col>=7)
        {
            row=row+1;
            col=0;
        }
    }
    printf("\n\tSun\tMon\tTue\tWed\tThu\tfri\tSat\n");
    for(i=0;i<6;i++)
    {
        for(j=0;j<7;j++)
        {
            if(arr[i][j]==0)
            printf("\t");
            else
            printf("\t%d",arr[i][j]);
        }
        printf("\n");
    }
}
__________________
Always TAG and SHARE your threads
Submit your site to TECH6 Directory
TECH6 on Facebook - Like Us

Would you like to Link To Us | Support TECH6 by going Premium
Know more about me at Vinayaks.com | Follow TECH6 at Twitter


Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes




All times are GMT +5.5. The time now is 07:28 PM.

Contact Us - Tech6.com - Link to Us - Advertise - Submit Site - Privacy Statement - TOS - Top