Example 34: Day Clock

Learn how to print 24 hours of a day using loops.

Problem

Write a program to print 24 hours of a day with suitable suffixes like AM, PM, Noon, and Midnight.

Example

Input Output
Nil 12 Midnight 1 AM 2 AM … 12 Noon 1 PM 2 PM … 10 PM 11 PM

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Note: Remember to start printing the hours of a day from 12 Midnight. Each hour should be separated by a single space.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.