Write a program that requires the user to enter the time in the 24-hour format and then display the time in the 12-hour format.
Input Format:
Enter a 24-hour time with the intermediate ":" symbol (half-width colon) in a row, as shown in figure12:34
It indicates 12: 34 points. When the number of hours or minutes is less than 10, there is no leading zero, such5:6
It indicates.
Tip: Add ":" To the scanf format string to allow scanf to process the colon.
Output Format:
Output the 12-hour time corresponding to this time in a row. The number format is the same as that of the input, followed by spaces, then follow the string "am" indicating the morning or the string "PM" indicating the afternoon ". For example,5:6 PM
"Indicates five o'clock P.M. Note: In English habits, it is considered to be afternoon at noon, so it is in the 24-hour format.12:00
It's in 12-hour format.12:0 PM
And 0 is considered as the next day, so yes0:0 AM
.
Input example:
21:11
Output example:
9:11 PM
#include "stdio.h"int main(){ int hour; int min; scanf("%d:%d",&hour,&min); if(hour>11) { if(hour==12) { printf("%d:%d PM",hour,min); } else { printf("%d:%d PM",hour-12,min); } } else { printf("%d:%d AM",hour,min); } return 0;}