clock c program

 Problem Statement

Write a c program to convert 12 hour clock time to 24 hour time.

Solution

#include<stdio.h>

#include<string.h>

int main()

{

    int hh,mm,ss;

    char a[10];

    scanf("%d%d%d%s",&hh,&mm,&ss,a);

    if((hh<=12)&&(mm<=59)&&(ss<=59))

    {

        if((strcmp(a,"pm")==0)||(strcmp(a,"PM")==0)&&(hh!=12)&&(hh!=0))

        {

            hh=hh+12;

        }

        if((strcmp(a,"am")==0)||(strcmp(a,"AM")==0)&&(hh==12))

        {

            hh=0;

        }

        printf("%0.2d:%0.2d:%0.2d",hh,mm,ss);

    }

    return 0;

}

Input

8 37 59 pm

Output

20:37:59

Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post