#include<stdio.h>
main()
{
int d,m,y;
int flag=1,isleap=1;
printf(“enter the date (dd/mm/yyyy): “);
scanf(”%d,%d,%d”,&d,&m,&y);
if(y%4==0 && y%100!=0 || y%400==0)
isleap=1;
if(y<=1850 || y>=2050)
flag=0;
if(m<1 || m>12)
flag=0;
if(d<1)
flag=0;
if(m==2)
{
if(d>28)
flag=0;
if(d=29 && isleap)
flag=1;
}
if(m==4 || m==6 || m==9 || m==11)
{ if(d>30)
flag=0;
}
else
flag=1;
if(flag=0)
printf(“not a valid date”);
if(flag=1)
printf(“enter the valid date”);
}
Dont intilialise isLeap as equal to 1. Initialise it to 0. Even if the years are not leap, it will incorrectly state so otherwise.
if(m==4 || m==6 || m==9 || m==11)
{ if(d>30)
flag=0;
}
Dont use “else flag=1” after this. It voids the earlier cases.
if(flag=0)
printf("not a valid date");
if(flag=1)
printf("enter the valid date");
This condition is wrong. You must use the comparison operator ==. So, correct statements are if(flag==0) and if(flag==1).
Same goes for d=29. It must be d==29 in that if statement.