Military Time (24hr to 12hr) - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Monday 6 November 2017

Military Time (24hr to 12hr)

#include<stdio.h>

int main()
{
    int milhour, milmin, hours;
    char afternoon;

    printf("enter the hours in military time:\n");
    scanf("%d", &milhour);

    printf("enter the minutes in military time: \n");
    scanf("%d", &milmin);

    if (milhour < 12)
    {
        hours = milhour;
        afternoon = 'A';
    }

    if (milhour >= 13)
    {
        hours = milhour - 12;
        afternoon = 'P';
    }

    printf("The time in 12 hour format is: ");
    printf("%d", hours);
    printf(":");
    printf("%d", milmin);
    printf("%c", afternoon);
}
OUTPUT
enter the hours in military time: 22

enter the minutes in military time:12

The time in 12 hour format is: 10:12p

No comments:

Post a Comment

Post Top Ad