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

  1. #include<stdio.h>
  2. int main() {
  3. int hh, mm, ss ;
  4. char t12[3];
  5. scanf("%d:%d:%d%s", &hh, &mm, &ss, t12) ;
  6. if (strcmp(t12,"PM")==0 && hh!=12) hh += 12 ;
  7. if (strcmp(t12,"AM")==0 && hh==12) hh = 0 ;
  8. printf("%02d:%02d:%02d", hh, mm, ss) ;
  9. return 0;
  10. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube