top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Algorithm for the calender?

0 votes

Suppose given a date how can we find out the day i.e. sunday, monday .....etc.

Please help me, google is confusing me.

posted Aug 18, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
#include <stdio.h>
#include <time.h>   // For mktime(),  strftime and struct tm
#include <string.h> // For memset()

int main()
    int month;
    int day;
    int year;
    char daybuf[20];
    struct tm time_str;

    printf("Enter the year (>= 1900) : ");
    scanf("%d", &year);
    printf("Enter the month number (1 -12) : ");
    scanf("%d", &month);
    printf("Enter the day number (1 - 31) : ");
    scanf("%d", &day);

    printf("Your enterd date is (dd/mm/yy) : %d/%d/%d\n", day, month, year);

    memset(&time_str, 0, sizeof(time_str));

    time_str.tm_year = year - 1900;     // Year since 1900
    time_str.tm_mon = month - 1;        // Month of year [0, 11]
    time_str.tm_mday = day;
    time_str.tm_isdst = -1;
      The value of tm_isdst shall be positive if Daylight Savings Time is in effect, 0 if Daylight Savings Time 
       is not in effect, and negative if the information is not available.
       For more info please look through the <time.h> file.

    if (mktime(&time_str) == -1)
    else {
        strftime(daybuf, sizeof(daybuf), "%A", &time_str);
            For more information how to get different contents of "structure tm" 
            do a "man 3 strftime"
        printf("\nOutput Day : %s\n", daybuf);
    return 0;
answer Aug 27, 2014 by Arshad Khan
Similar Questions
+2 votes

using adjacency matrix representation of graph?

+2 votes

Provide an algorithm to add and multiply two large integers which cannot be represented by built-in types, C code would be a great help?

+6 votes

Looking for basic steps to analyse the algorithm.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.