techpreparation-homepage

Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Visual Basic Interview Question
ASP .NET Interview Questions
C++ Interview Questions
C Interview Questions
                              .........More

Programming Source Codes
C/C++ Source Codes
C# Source Codes
                              .........More

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
                              .........More

Tutorials
C Tutorial
C++ Tutorial
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

 

 

  

C/C++ Source Codes

C calendar from 1752

#include<stdio.h>
#define Y 1752
// 1/1/1752 Saturday
/* the The calendar as we know it only came into effect (in England) in 1752,
replacing the Julian calendar. Changes included cutting 11 or more days out
of the calendar and changing the first day of the year from march 21st to January 1st,
and so this calculation method should not be used for dates before this changeover.
*/
#define BASE 5

void day(int dd, int mm, int yy);
void display(int, int);
int _MONTH[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *days[] = {"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"};

int main() {
char ch = 'y';
int mm,yy,dd;
do {
printf("\nEnter dd ");
scanf("%ld",&dd);
printf("\nEnter mm [1-12] ");
scanf("%ld",&mm);
printf("Enter yyyy ");
scanf("%ld",&yy);

if( (yy%4==0) && ( (yy%100!=0) '' (yy%400==0) ) )
_MONTH[2]=29;

day(dd,mm,yy);
printf("\n\n\n\nPress 'x' to EXIT\n");
fflush(stdin);
ch = getchar();
}while(ch != 'x');
return 0;
}

void day(int dd,int mm, int yy) {
int i,md=0,leap=0,track, temp;
unsigned int d,yrd;

for(i=Y;i<yy;i++) {
if( (i%4==0) && ((i%100!=0) '' (i%400==0)))
leap++;
}

for(i=1; i < mm; i++)
md = md + _MONTH[i];

yrd = (yy-Y) * 365;
d=yrd+leap+md+BASE;
temp = d + dd;
temp = temp % 7;
printf("day is : %s",days[temp]);
track=d%7;
display(track,mm);
}

void display(int track,int m) {
int dt,loop;
printf("\n\n\n\t\t");
printf("MON\tTUES\tWED\tTHURS\tFRI\tSAT\tSUN\n\n");

for(loop=0; loop < track + 2; loop++) /*t+2 due to two additional \t*/
printf("\t");

for(dt=1; dt <= _MONTH[m]; dt++) {
if(track % 7 == 0 && track != 0)
printf("\n\n\t\t");
printf("%d",dt);
printf("\t");
track++;
}
}


<<<----- Return to C/C++ Source Code Questions Page.


Have a Question ? post your questions here. It will be answered as soon as possible.

Check Object Oriented Interview Questions for more Object Oriented Interview Questions with answers

Check Data Structure Interview Questions for more data structure interview questions with answers