Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,244 questions

52,261 answers

573 users

How to calculate the future occurrences of Friday the 13th in C

1 Answer

0 votes
#include <stdio.h>
#include <time.h>

void findFridayThe13ths(int startYear, int endYear) {
    for (int year = startYear; year <= endYear; ++year) {
        for (int month = 1; month <= 12; month++) {
            // Create a tm structure for the 13th day of the current month and year
            struct tm timeStruct = {0};
            timeStruct.tm_year = year - 1900; // tm_year is years since 1900
            timeStruct.tm_mon = month - 1;    // tm_mon is 0-based (0 = January)
            timeStruct.tm_mday = 13;          // 13th day of the month

            // Normalize the tm structure to get the correct day of the week
            mktime(&timeStruct);

            // Check if the 13th is a Friday (tm_wday == 5)
            if (timeStruct.tm_wday == 5) {
                printf("Friday the 13th: %d-%02d-13\n", year, month);
            }
        }
    }
}

int main() {
    int startYear = 2025; // Starting year
    int endYear = 2031;   // Ending year

    findFridayThe13ths(startYear, endYear);

    return 0;
}


/*
run:

Friday the 13th: 2025-06-13
Friday the 13th: 2026-02-13
Friday the 13th: 2026-03-13
Friday the 13th: 2026-11-13
Friday the 13th: 2027-08-13
Friday the 13th: 2028-10-13
Friday the 13th: 2029-04-13
Friday the 13th: 2029-07-13
Friday the 13th: 2030-09-13
Friday the 13th: 2030-12-13
Friday the 13th: 2031-06-13

*/

 



answered May 31, 2025 by avibootz
...