Page Rank Checker

Thursday 15 May 2014

Calender In C-Takes Year And Prints Day At 1 Jan


I am Posting here this is article basically for the begginers in C programing. The programme given below will first ask the user to type the year (year should be greater than 2000) and then tell us that what will be the day at 1January of the year enter NEW
Description : I am Posting here this is article basically for the begginers in C programing. The programme given below will first ask the user to type the year (year should be greater than 2000) and then tell us that what will be the day at 1January of the year entered by the user. For using it simply copy and paste the code given below and compile it using any c compiler.

#include<stdio.h>
#include<conio.h>
int cal(int );
int prnt(int );
void main()
{
   clrscr();
   int yr;
   printf("enter year ");
   scanf("%d",&yr);
   cal(yr);
   getch();
}
int cal(int yr)
{
   int diff, lp_yr;
   unsigned int totds;
   diff=yr-2001;                 \*calculate number of years between provided year and 2001 *\
   lp_yr=diff/4;                    \*calculate number of leap years between provided year and 2001*\
   totds=365*diff+lp_yr+1; \*calculate total days between 1 Jan of provided year and 1 Jan 2001 *\
   printf("%u\n\n",totds);      \*prints total days between 1 Jan provided year and 1 Jan 2001 *\
   prnt(totds);
}
int prnt(int totds)
{
   int dycd;
   dycd=totds%7; \*This is the main part of the program this is purely mathematical part see calender and try to understand if have any doubt give comments I will surely give you reply*\
   switch (dycd)
  {
   case 1:
     printf("monday");
     break;
   case 2:
     printf("tuesday");
     break;
   case 3:
     printf("wednesday");
     break;
   case 4:
     printf("thursday");
     break;
   case 5:
     printf("friday");
     break;
   case 6:
     printf("saturday");
     break;
   case 0:
     printf("sunday");
     break;
  }
}