#include<stdio.h>
int main(void)
{
int x,y
printf("Enter a 24-hour time: ")
scanf("%d:%d",&x,&y)
if (x<12&&x>0)
printf("Equivalent 12-hour time: %d:%d AM\n",x,y)
else if(x==0)
{x=12
printf("Equivalent 12-hour time: %d:%d AM\n",x,y)}
else if(x>12)
{x=x-12
printf("Equivalent 12-hour time: %d:%d PM\n",x,y)}
else if(x==12)
printf("Equivalent 12-hour time: %d:%d PM\n",x,y)
return 0
}
#include<reg51.h>#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}//0-9
unsigned char sec=55,min=59,hour=12,scanled
unsigned char key,mode,time
unsigned char disdat[8]
sbit key1=P1^4
sbit key2=P1^5
void delay(unsigned int x)
{
unsigned int i,j
for(i=0i<xi++)
for(j=0j<120j++)
}
void dischg()
{
disdat[0]=sec%10
disdat[1]=sec/10
disdat[2]=min%10
disdat[3]=min/10
disdat[4]=hour%10
disdat[5]=hour/10
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c
TL0=0xb0
time++
switch(mode)
{
case 0:
if(time==20)
{
time=0
sec++
if(sec>59)
{
sec=0
min++
if(min>59)
{
min=0
hour++
if(hour>12)hour=0
}
}
}
break
case 1:
if(time==20)
{
time=0
if(sec>0)sec--
else if(min>0){sec=59min--}
else if(hour>0){sec=59min=59hour--}
else {hour=0min=0sec=0}
}
break
}
dischg()
}
void t1isr() interrupt 3 //显示
{
TH1=0xec
TL1=0x78
switch(scanled)
{
case 0:
P3=0x04
P2=~ledtab[disdat[5]]
break
case 1:
P3=0x08
P2=~ledtab[disdat[4]]&0x7f
break
case 2:
P3=0x10
P2=~ledtab[disdat[3]]
break
case 3:
P3=0x20
P2=~ledtab[disdat[2]]&0x7f
break
case 4:
P3=0x40
P2=~ledtab[disdat[1]]
break
case 5:
P3=0x80
P2=~ledtab[disdat[0]]
break
default:break
}
scanled++
scanled%=6
}
main()
{
TMOD=0x11
TH0=0x3c
TL0=0xb0
TH1=0xec
TL1=0x78
TR1=1
TR0=0
ET0=1
ET1=1
EA=1
sec=0
min=0
hour=0
scanled=0
time=0
mode=0
dischg()
while(1)
{
if(key1==0)
{
while(key1==0)
TR0=1
}
if(key2==0)
{
while(key2==0)
TR0=0
}
}
}
#include <stdio.h>int main()
{
int h,m
scanf("%d:%d",&h,&m)//输入24小时制的时间
if(h>=12) //如果h不小于12
{
printf("PM ")//输出PM,表示下午
if(h>12) h-=12//如果h>=13,则将h减12
}
else printf("AM ")//否则输出AM,表示上午
printf("%d:%02d",h,m)//输出12小时制的时间
return 0
}
//运行示例:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)