如何使用printf在字符串中打印多个变量?

时间:2016-01-04 19:07:51

标签: c printf syntax-error

我想找到两个数字的最大值,然后打印出来。我想要打印所有三个数字。我使用以下代码。

#include<stdio.h>
#include<conio.h>
main()
{
     //clrscr();
     int a,b,c;
     printf("insert two numbers:");
     scanf("%d%d", &a, &b);
     c = (a>b) ? a : b;
     printf("\nmaximum of %d",a," and %d",b,"  is = %d" c);
     getch();

}

但是,我收到两个语法错误(请参见附图)。 有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:16)

将输出打印的行更改为:

printf("\nmaximum of %d and %d is = %d",a,b,c);

查看文档here

答案 1 :(得分:3)

printf("\nmaximum of %d and %d is = %d",a,b,c);