Answer to Question #12063 in C# for Jenny

Question #12063
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");
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS