C语言PRINTF怎么同时输出整形变量和符号

#include<stdio.h>
void main()
{
int a,b,c,d;
scanf("%d:%d:%d",&a,&b,&c);
if(a>12)
{
d=a-12;
printf("%d:%d:%d%s\n",d,b,c"AM");

}
else
printf("%d:%d:%d%s\n",a,b,c"PM");
}
这个程序是将24小时变成12小时的 可是错误是
D:\demo2\demo2.cpp(9) : error C2143: syntax error : missing ')' before 'string'
D:\demo2\demo2.cpp(9) : error C2059: syntax error : ')'
D:\demo2\demo2.cpp(13) : error C2143: syntax error : missing ')' before 'string'
D:\demo2\demo2.cpp(13) : error C2059: syntax error : ')'
Error executing cl.exe.
有谁懂得啊·····

和输出一个变量类似,只要在前后都加上对应内容即可,如printf("%d,%d\n",a,b);
printf("输出格式类型",变量);
例如
int a = 10;
int b = 20;
printf("%d,%d\n",a,b);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-12
#include<stdio.h>
void main()
{
int a,b,c,d;
scanf("%d:%d:%d",&a,&b,&c);
if(a>12)
{
d=a-12;
printf("%d:%d:%dAM\n",d,b,c);

}
else
printf("%d:%d:%dPM\n",a,b,c);
}
直接在""里面输入,试试我给的代码!
第2个回答  2012-03-12
printf("%d:%d:%d AM\n",d,b,c);
printf("%d:%d:%d PM\n",d,b,c);
直接这样就可以了
你那样在字符串前面少了逗号
第3个回答  2012-03-12
printf("%d:%d:%dAM\n",d,b,c);这样
第4个回答  推荐于2016-07-11
#include<stdio.h>
void main()
{
int a,b,c,d;
scanf("%d:%d:%d",&a,&b,&c);
if(a>12)
{
d=a-12;
printf("%d:%d:%d%s\n",d,b,c,"AM");//改过

}
else
printf("%d:%d:%d%s\n",a,b,c,"PM");//改过
}本回答被提问者和网友采纳