Write a C program to check date is valid or not (2 Methods)

By | December 3, 2016

C program to check date is valid or not 


Write a C program to check date is valid or not.This program will read date from user and validate whether entered date is correct or not with checking of leap year.


The program given below first accepts a date from the keyboard, determines whether it is valid or not using the algorithm given above and then prints an appropriate message.

Let us use variables dd,mm and yy (all of type int)to represent the day, month and year in a given date.

The given date is valid only if year (yy)is non-zero, month (mm)is in the range 1 to 12 and day of month (dd) is in the range 1 to mdays, the number of days in a given month mm.

Observe that the %d format Specifiers in the scanf format string are separated by ‘/’ characters as “%d/%d/%d”.

Such non-format characters in the format string of the scanf statement must be entered by the user at the indicated position. Thus, the user must enter the date in the format dd/mm/yyyy.


Below is the source code of the C program to check date is valid or not which is successfully compiled and run on the windows system.The Output of the program is shown below.


1 . SOURCE CODE : :



OUTPUT : : 




2. Write a C program to check date is valid or not.This program will read date from user and validate whether entered date is correct or not with checking of leap year.


LOGIC : :


  • Enter date.
  • Check year validation, if year is not valid print error.
  • If year is valid, check month validation (i.e. month is between 1 to 12), if month is not valid print error.
  • If month is valid, then finally check day validation with leap year condition, here we will day range from 1 to 30, 1 to 31, 1 to 28 and 1 to 29.
  • If day is valid print date is correct otherwise print error.

Below is the source code of the C program to check date is valid or not which is successfully compiled and run on the windows system.The Output of the program is shown below.


2 . SOURCE CODE : :



OUTPUT : : 


2 thoughts on “Write a C program to check date is valid or not (2 Methods)

  1. Pingback: Write a C program to calculate Binary Addition and Binary Subtraction

  2. Pingback: Write a C program to check given string is valid IPv4 address or not

Leave a Reply