Program to validate date, month and year

Program to validate date, month and year


Program:


#include<stdio.h>
void main()
{
int dt,mnth,yr;
printf("Enter date,month and year: ");
scanf("%d%d%d",&dt,&mnth,&yr);
if(yr<1||sizeof(yr)>2)
{
printf("Please enter appropriate year!!!");
}
else if(mnth<1||mnth>12)
{
printf("Please enter appropriate month!!!");
}
else if(dt<1 || dt>31)
{
printf("Please enter appropriate date!!!");
}
else if(dt==31&&mnth==8)
{
printf("Date is Valid!!!");
}
else if(dt==29&&mnth==2&&(yr%4==0))
{
printf("Date is Valid!!!");
}
else if(dt==29&&mnth==2&&(yr%4!=0))
{
printf("Please enter appropriate date!!!");
}
else if(dt==30&&mnth==2)
{
printf("Please enter appropriate date!!!");
}
else if(dt>30&&(mnth)%2==0)
{
printf("Please enter appropriate date!!!");
}
else
{
printf("Date is Valid!!!");
}
}






Output:




April does not has 31 days


Year can't be negative.


Month can't be negative.


Date can't be negative.


Non-leap year's February does not has 29 days.


Leap year's February does not has 29 days.



No comments:

Post a Comment