Do you know the day of the week you were born?

This is a discussion on Do you know the day of the week you were born? within the C Programming forums, part of the General Programming Boards category; Easy enough because I know some probably need the help: Code: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) ...

  1. #16
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    Easy enough because I know some probably need the help:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
    	int a, y, m, d;
    	int month, day, year;
    	char buffer[16];
    	
    	char weekDay[][10] = {"Sunday", "Monday", "Tuesday", "Wednesday",
    							"Thursday", "Friday", "Saturday"};
    							
    	char monthName[][10] = { "", "January", "February", "March", "April",
    							 "May", "June", "July", "August", "September",
    							 "October", "November", "December"};
    	
    	printf("Enter date: mm/dd/yyyy: ");
    	fgets(buffer, 11, stdin);
    	buffer[2] = '\0';
    	buffer[5] = '\0';
    	month = atoi(buffer);
    	day = atoi(&buffer[3]);
    	year = atoi(&buffer[6]);
    	
    	a = (14 - month) / 12;
    	y = year - a;
    	m = month + 12 * a - 2;
    	d = (day + y + y / 4 - y / 100 + y / 400 + 31 * m / 12) % 7;
    	
    	printf("\n%s/%02i/%04i was a %s\n\n", monthName[month], day, year, weekDay[d]);
    	printf("Press `Enter' to continue . . . ");
    	getchar( ); getchar( );
    	return(0);
    }

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Thank you for your consideration.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. day of week
    By s_ny33 in forum C Programming
    Replies: 18
    Last Post: 11-02-2005, 11:56 AM
  2. Force end
    By Redattack34 in forum C++ Programming
    Replies: 9
    Last Post: 09-07-2005, 12:16 AM
  3. The day of the week America was discovered
    By Gustaff in forum C Programming
    Replies: 3
    Last Post: 08-12-2005, 10:47 AM
  4. debug program
    By new_c in forum C Programming
    Replies: 3
    Last Post: 03-18-2002, 11:50 PM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21