#include<stdio.h> #include<string.h> #include<time.h> int main() { int h, m; char a[3]; scanf("%d", &h); scanf("%d", &m); scanf(" %s",a); if(((strcmp(a,"AM") == 0) || (strcmp(a,"am") == 0))&& (h == 12)) { h =0; printf("%02d:%02d", h, m); } else if((strcmp (a,"PM")==0)&&((h!=0)&&(h!=12))) { h=h+12; printf("%02d:%02d",h,m); } }
1/6/2020 12:54:59 PM
Vishwesh Patel2 Answers
New AnswerVishwesh Patel you nees to take user input in given format XX:XX and you didn't nees to check for lower case input you also don't need to use two print statements just reduce that here is what I decoded from your code #include<stdio.h> #include<string.h> #include<time.h> int main() { int h, m; char a[3]; scanf("%d:%d %s", &h, &m, a) ; if(((strcmp(a,"AM") == 0)&& (h == 12))) h =0; else if((strcmp (a,"PM")==0)&&((h!=0)&&(h!=12))) h=h+12; printf("%02d:%02d",h,m); }
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message