Wednesday 24 July 2013

Chapter 2 solutions problem[C](d)

Question-According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.
Solution-
it's nothing but a simple program, it can be easily done by using above concept. that's how it goes.

#include<stdio.h>
int main()
{
int yr=2012,totdays,normaldays,leapdays,k=yr-1;
printf("Enter any year\n");
scanf("%d",&yr);
normaldays=365*k;
leapdays=k/4+k/400-k/100;
totdays=normaldays+leapdays;
if(totdays%7==0)
printf("Monday\n");
if(totdays%7==1)
printf("Tuesday\n");
if(totdays%7==2)
printf("Wednesday\n");
if(totdays%7==3)
printf("Thursday\n");
if(totdays%7==4)
printf("Friday\n");
if(totdays%7==5)
printf("Saturday\n");
if(totdays%7==6)
printf("Beloved Sunday");
return 0;

8 comments:

  1. It is wrong Sir According to Calender it was sunday on january 2012 but here in this programme it was monday on january 2012.

    ReplyDelete
    Replies
    1. Hi, thanks for your interest . I have realized my mistake. It was counting 1900 as well. I have corrected my program . hopefully you will get the right answer now . Enjoy :)

      Delete
    2. Thanks Sir for your reply,i had done it earlier but it is very nice of you that you correct this programme,keep coming you solutions and i will be glad that you could provide solutions for let us c++ programme also.

      Delete
    3. sir the question was wrong.....date is 01/01/01 NOT 01/01/1900

      Delete
    4. Hi , is it ? ok , i will recheck it once again and will make the corrections . Thank you very much for the help. highly appreciate it ..Please let me know if you find any other errors ..

      Delete
  2. #include
    int main()
    {
    int i,y,c;
    printf("enter the year\n");
    scanf("%d",&y);
    c = 0;
    //n = y - 2001;

    for(i=2001;i<=y;i++)
    {
    if(i % 4 == 0)
    c = c + 1 + 1;
    else
    c = c + 1 ;
    }
    printf("%d\n",c);
    if(c > 7)
    c = c % 7;
    printf("%d\n",c);
    if(c==0)
    printf("sunday\n");

    if(c==1)
    printf("monday\n");

    if(c==2)
    printf("tuesday\n");

    if(c==3)
    printf("wednesday\n");

    if(c==4)
    printf("thursday\n");

    if(c==5)
    printf("friday\n");

    if(c==6)
    printf("saturday");
    return 0;
    }

    ReplyDelete
  3. didn'd understand the logic of leap days :(

    ReplyDelete
  4. didn'd understand the logic of leap days :(

    ReplyDelete