Formula for calculating the day of week from a given date
The formula for calculating the day is
day=(y + j + a  b + ab) %7
j = julian day of the date
y = year of given date (in 4 digits)
a = int part of (y1)/4
b = int part of (y1)/100
ab=int part of (y1)/400
The value of variable day tells us the day of week
Value of variable day
 Name of day of week


0
 Saturday

1
 Sunday

2
 Monday

3
 Tuesday

4
 Wednesday

5
 Thursday

6
 Friday

In the above formula, julian day of a date represents the day of year.
Julian day of:
1st Jan = 1
5th Feb = 36
31st Dec = 365 (366 if leap year)
Code (In 'C' Language)
#include<stdio.h> #include<conio.h> void main() { int d,m,y,j,a,b,ab,day; printf("Enter date (dd/mm/yyyy) : "); scanf("%d/%d/%d",&d,&m,&y); j=d; switch(m1) { case 11: j+=30; case 10: j+=31; case 9: j+=30; case 8: j+=31; case 7: j+=31; case 6: j+=30; case 5: j+=31; case 4: j+=30; case 3: j+=31; case 2: j+=28; case 1: j+=31; } if(y%4==0 && y%100 !=0  y%400==0) if(m!=1&&m!=2) j=j+1; a=(y1)/4; b=(y1)/100; ab=(y1)/400; day=(y+j+ab+ab)%7; switch(day) { case 0: printf("Saturday\n"); break; case 1: printf("Sunday\n"); break; case 2: printf("Monday\n"); break; case 3: printf("Tuesday\n"); break; case 4: printf("Wednesday\n"); break; case 5: printf("Thursday\n"); break; case 6: printf("Friday\n"); break; } }
Program to find the LCM and HCF of two numbers
#include<stdio.h> #include<conio.h> void main() { int a,b,c,d; printf("Enter 1st Number: "); scanf("%d",&a); printf("Enter 2nd Number: "); scanf("%d",&b); c=a; d=b; while(c!=d) { if(c<d) c=c+a; else d=d+b; } printf("LCM of %d and %d is %d\n",a,b,c); c=a; d=b; while(c!=d) { if(c>d) c=cd; else d=dc; } printf("HCF of %d and %d is %d\n",a,b,c); }
Comments
The running time of the program can be optimized. Note that HCF x LCM of two numbers is the product of them. Calculation HCF requires less computation than calculating the LCM, you could then extend the program to find the LCM and HCF of arbitrary n input numbers. The calendar program too needs optimization.