Skip to content

luc084.c

Problem Statement

Define a function that compares two given dates. Return 0 if equal, otherwise return 1.

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 08 Feb 2026
License MIT License (See the LICENSE file for details)
Difficulty Beginner (index: 3 / 10)

Concepts

Beta Feature

This concept detection system is still in beta and may occasionally show incorrect or incomplete results.

  • Recursion

Actions

Raw View on GitHub

You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct date
{
    int day;
    int month;
    int year;
};

int compare_dates(struct date d1, struct date d2);

int main()
{
    struct date date1, date2;

    printf("Enter Date 1 (dd mm yyyy): ");
    scanf("%d %d %d", &date1.day, &date1.month, &date1.year);

    printf("Enter Date 2 (dd mm yyyy): ");
    scanf("%d %d %d", &date2.day, &date2.month, &date2.year);

    if (compare_dates(date1, date2) == 0)
        printf("The dates are Equal.\n");
    else
        printf("The dates are NOT Equal.\n");

    return 0;
}

int compare_dates(struct date d1, struct date d2)
{
    if (d1.day == d2.day && d1.month == d2.month && d1.year == d2.year)
        return 0;
    else
        return 1;
}

Explanation

Explain with AI

Copy the prompt below and paste it into any AI assistant.

    You are explaining a C programming code to a beginner.

    STRICT RULES:

    - Only use the given code. Do NOT assume anything not present.

    - Do NOT add extra examples.

    - Keep explanation clear and short.

    - If something is unclear, say "Not clear from code".

    - Follow the exact format below. Do NOT change headings.

    FORMAT:

    [START]

    ## What it does

    (Explain the overall purpose in 1-2 sentences)

    ## Step-by-step

    (Explain how the code works in steps, simple language)

    ## Key Concepts

    (List concepts like loop, condition, function, etc.)

    ## Notes

    (Mention any limitations, errors, or assumptions)

    [END]

    CODE (luc084.c):

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>

    struct date
    {
        int day;
        int month;
        int year;
    };

    int compare_dates(struct date d1, struct date d2);

    int main()
    {
        struct date date1, date2;

        printf("Enter Date 1 (dd mm yyyy): ");
        scanf("%d %d %d", &date1.day, &date1.month, &date1.year);

        printf("Enter Date 2 (dd mm yyyy): ");
        scanf("%d %d %d", &date2.day, &date2.month, &date2.year);

        if (compare_dates(date1, date2) == 0)
            printf("The dates are Equal.\n");
        else
            printf("The dates are NOT Equal.\n");

        return 0;
    }

    int compare_dates(struct date d1, struct date d2)
    {
        if (d1.day == d2.day && d1.month == d2.month && d1.year == d2.year)
            return 0;
        else
            return 1;
    }