source: buchla-68k/orig/DATE/DAY.C@ ee49131

Last change on this file since ee49131 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.6 KB
Line 
1
2/* ---------------------------------------------------------------------- */
3/* Program to calculate # of days between two dates */
4/* ---------------------------------------------------------------------- */
5
6/* Please note that this program only works from 01-12-1600 A.D. onward */
7
8#include <stdio.h>
9
10struct date /* structure to hold date */
11 {
12 int month;
13 int day;
14 int year;
15 } date_1;
16
17
18long int funct1 (y,m) /* part of # of days calc. */
19 int y, m;
20 {
21 long int result;
22 if ( m <= 2 )
23 y -= 1;
24 result = y;
25 return (result);
26 }
27
28long int funct2 (m)
29 int m;
30 {
31 long int result;
32 if ( m <= 2 )
33 result = m + 13;
34 else
35 result = m + 1;
36 return(result);
37 }
38
39/* Function to calculate the number of days in dates */
40
41long int day_count (m, d, y)
42 int m, d, y;
43 {
44 long int number;
45 number = 1461 * funct1(y,m) / 4 + 153 * funct2(m) / 5 + d;
46
47 return (number);
48 }
49
50main ()
51{
52 long int number_of_days1;
53 int day_of_week, screw_up = 0;
54
55 printf("\n\n*****************************************************************\n");
56 printf("THIS PROGRAM WILL COMPUTE THE DAY OF THE WEEK (SUNDAY - SATURDAY)\n");
57 printf("\t\tTHAT A GIVEN DATE WILL FALL ON\n");
58 printf("*****************************************************************\n\n");
59
60 printf ("Enter a date (mm dd yyyy) i.e. 03 12 1985 \n");
61 scanf ("%d %d %d", &date_1.month, &date_1.day, &date_1.year);
62
63 number_of_days1 = day_count (date_1.month, date_1.day, date_1.year);
64
65 printf ("\nThe date is: " );
66
67 day_of_week = (number_of_days1 - 621049) % 7;
68
69 switch (day_of_week)
70 {
71 case 0 :
72 printf ("Sunday,");
73 break;
74 case 1 :
75 printf ("Monday,");
76 break;
77 case 2 :
78 printf ("Tuesday,");
79 break;
80 case 3 :
81 printf ("Wednesay,");
82 break;
83 case 4 :
84 printf ("Thursday,");
85 break;
86 case 5 :
87 printf ("Friday,");
88 break;
89 case 6 :
90 printf ("Saturday,");
91 break;
92 default:
93 printf ("Something is screwed up -- Maybee you entered\n");
94 printf ("a date earlier than 01 12 1600\n\n");
95 screw_up = 1;
96 }
97 printf (" %02d/%02d/%02d\n", date_1.month, date_1.day, date_1.year);
98
99}
100
101
102
103
Note: See TracBrowser for help on using the repository browser.