1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Day for a particular date entered

Discussion in 'C' started by amanbaua, Sep 6, 2009.

  1. amanbaua

    amanbaua New Member

    Joined:
    Aug 23, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    This is the program to figure out the day entered on a particular date but remember this code works between the years 1900 to 1999 suppose u enter the date as 5/1/1957 then the day comes out to be saturday so try it out and post ur comments

    Code:
    /*this is d program to figure out the day on a particular date entered*/
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    
    void main()
    {
    	clrscr();
    	int d,m,y,year,month,day,i,n;
    	printf("Enter the date :	");
    	scanf("%d%d%d",&day,&m,&y);
    	if( day>31 || m>12 || (y<1900 || y>=2000) )
    	{
    		printf("INVALID INPUT");
    		getch();
    		exit(0);
    	}
    	year = y-1900;
    	year = year/4;
    	year = year+y-1900;
    	switch(m)
    	{
    	case 1:
    	case 10:
    		month = 1;
    		break;
    	case 2:
    	case 3:
    	case 11:
    		month = 4;
    		break;
    	case 7:
    	case 4:
    		month = 0;
    		break;
    	case 5:
    		month = 2;
    		break;
    	case 6:
    		month = 5;
    		break;
    	case 8:
    		month = 3;
    		break;
    	case 9:
    	case 12:
    		month = 6;
    		break;
    	}
    	year = year+month;
    	year = year+day;
    	d= year%7;
    	switch(d)
    	{
    	case 0:
    		printf("Day is SATURDAY");
    		break;
    	case 1:
    		printf("Day is SUNDAY");
    		break;
    	case 2:
    		printf("Day is MONDAY");
    		break;
    	case 3:
    		printf("Day is TUESDAY");
    		break;
    	case 4:
    		printf("Day is WEDNESDAY");
    		break;
    	case 5:
    		printf("Day is THURSDAY");
    		break;
    	case 6:
    		printf("Day is FRIDAY");
    		break;
    	}
    
    	getch();
    
    }
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Any special reason it does not work for 2000+ year
     
  3. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    if( day>31 || m>12 || (y<1900 || y>=2000) )
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Seen that. I was talking about why that condition is there at all
     
  5. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    :lol: I can't imagine but may be say just to put a number value there ;) guessing 2000 :D
     
  6. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    It would be nice if the logic is also explained with post, one can understand what is being done but it is also necessary to know why it is done.
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Moved to forum instead of articles.
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    amanbua: it would be good if you fixed this code so that it would work for ANY year, not just 1900-1999. Then post the new code.

    I don't see much point in the code as it stands; anyone who wants to use it will want it to work for today, and you've had 10 years to fix it to work in this century, so there's no excuse really for it only supporting last century.
     

Share This Page