Please help me create a program that needs in a time of the day in 24-hour notation and output it in a 12 hour notation.For example, if the input is 1343,the output should be 1:45PM, if input is 920, output should be 9:20 AM.Consider 12:00 midnight as 12:00 AM and 12:00 noon as 12:00AM.
1
Expert's answer
2012-07-20T07:13:39-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Question12063 { class Program { static void Main(string[] args) { Console.Write("Enter time: "); int time = int.Parse(Console.ReadLine()); int hours = time / 100; int minutes = time % 100; if(hours <= 12) Console.WriteLine(hours+":"+minutes+"AM"); else Console.WriteLine((hours % 12)+":"+minutes+"PM"); } } }
Comments
Leave a comment