C language to convert the 24 hour system to the 12 hour system
- 2020-04-02 03:07:38
- OfStack
This article illustrates the C language's method of converting 24-hour system to 12-hour system. Share with you for your reference. The specific implementation method is as follows:
#include <stdio.h>
int main()
{
int n, m;
printf("Enter a 24-hour time:");
scanf_s("%d:%d",&n,&m);
if (n < 0)
{
printf("Error1!n");
system("PAUSE");
return 1;
}
else if (n < 12)
{
printf("Equivalent 12-hour time: %2d:%2d AMn", n, m);
}
else if ((n >= 12) && (n < 24))
{
n -= 12;
printf("Equivalent 12-hour time: %2d:%2d PMn", n,m);
}
else
{
printf("Error2!n");
system("PAUSE");
return 2;
}
system("PAUSE");
return 0;
}
Hope that the article described in the C programming language for you to help.