输入24小时制时间 输出12小时制时间的程序 5
#include<stdio.h>intmain(void){intx,y;printf("Entera24-hourtime:");scanf("%d:%d",&x,&...
#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;
}
我想知道我错在哪儿了 展开
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<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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询