03-3. 12-24 hour system (15)

Source: Internet
Author: User

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:34It indicates 12: 34 points. When the number of hours or minutes is less than 10, there is no leading zero, such5:6It 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:00It's in 12-hour format.12:0 PMAnd 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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.