如何使用 printf 在字符串中打印多个变量? [英] How can you print multiple variables inside a string using printf?

查看:78
本文介绍了如何使用 printf 在字符串中打印多个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

将打印输出的行更改为:

Change the line where you print the output to:

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

查看文档此处

这篇关于如何使用 printf 在字符串中打印多个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆