C Program to print the date in legal form

The following is a C program to print the date in legal format:

Expected Output:

1st run:

2nd run:

How it works

In informal writing, numbers in a date are usually separated by / or -.  For example:

05/11/15
05-11-2015

However, In legal and formal documents, dates are written in full. For example:

21st Dec 2012
December 21st, 2012

Here is how the above program works:

  • The body of the program starts by defining three variables: day, mon and year.
  • In lines 16-20, we have defined an array of character pointers containing the name of the months we would like to display.
  • Next, we ask the user to enter a date.
  • The if-else statement in lines 27-49, prints the day suffix (i.e “st”, “nd”, “rd” or “th”)
  • Finally, the print statement in line 51 prints month and year.

 

Recommended Reading:

Leave a Comment

%d bloggers like this: