【问题标题】:How can you print multiple variables inside a string using printf?如何使用 printf 在字符串中打印多个变量?
【发布时间】:2016-04-08 11:24:22
【问题描述】:

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

#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();

}

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

【问题讨论】:

  • '\n' 放在末尾而不是开头,因为它可能不会打印任何内容,除非出现另一个'\n' 或您明确调用fflush()。另外,如果可以,请不要学习 conio.hmain() 必须返回 int
  • 欢迎来到 Stack Overflow。请注意,在这里说“谢谢”的首选方式是投票赞成好的问题和有用的答案(一旦你有足够的声誉这样做),并接受对你提出的任何问题最有帮助的答案(这也给出了你的声誉小幅提升)。请查看About 页面以及How do I ask questions here?What do I do when someone answers my question?

标签: c printf syntax-error


【解决方案1】:

将打印输出的行更改为:

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

请参阅文档here

【讨论】:

    【解决方案2】:
    printf("\nmaximum of %d and %d is = %d",a,b,c);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多