Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,903 questions

14,810 answers

573 users

How to check if date is valid in C

1 Answer

0 votes
#include<stdio.h>

int is_date_valid(int d, int m, int y) {
     if (y >= 1900 && y <= 9999) {
        if (m >= 1 && m <= 12) {
            if ((d >= 1 && d <= 31) && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12))
                return 1;
            else if ((d >= 1 && d <= 30) && (m == 4 || m == 6 || m == 9 || m == 11))
                return 1;
            else if ((d >= 1 && d <= 28) && (m == 2))
                    return 1;
            else if (d == 29 && m == 2 && (y % 400 == 0 ||(y % 4 == 0 && y % 100 !=0)))
                return 1;
            else
                return 0;
        }
        else {
            return 0;
        }
    }
    else {
        return 0;
    }
}

int main() {
    int d = 10, m = 4, y = 2019;

    if (is_date_valid(d, m, y))
        printf("valid");
    else
        printf("not valid");
}


/*
run:

valid

*/

 




answered Apr 10 by avibootz
...