HackerRank C- Time Conversion
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.
timeConversion has the following parameter(s):
s: a string representing time in 12 hour format
- #include<stdio.h>
- int main() {
- int hh, mm, ss ;
- char t12[3];
- scanf("%d:%d:%d%s", &hh, &mm, &ss, t12) ;
-
- if (strcmp(t12,"PM")==0 && hh!=12) hh += 12 ;
- if (strcmp(t12,"AM")==0 && hh==12) hh = 0 ;
-
- printf("%02d:%02d:%02d", hh, mm, ss) ;
- return 0;
- }