How can you print multiple variables inside a string using printf?

此生再无相见时 提交于 2019-11-30 04:39:48

问题


I want to find the maximum value of two numbers, and print it. I want to print all three numbers. I am using the following code.

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

}

However, I receive two syntax errors (Please find the attached figure). Could anybody help me out with it?


回答1:


Change the line where you print the output to:

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

See the docs here




回答2:


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


来源:https://stackoverflow.com/questions/34598089/how-can-you-print-multiple-variables-inside-a-string-using-printf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!