Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HackerRank - Algorithms - Warmup - Time Conversion
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(void)
{
int hours, minutes, seconds;
char time[3];
scanf("%d:%d:%d%s", &hours, &minutes, &seconds, time);
if (hours < 12 && (strcmp("PM",time) == 0))
{
hours += 12;
}
if (hours == 12 && (strcmp("AM",time) == 0))
{
hours = 0;
}
printf("%02d:%02d:%02d", hours, minutes, seconds);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.