簡體   English   中英

如何使用 printf 在字符串中打印多個變量?

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

我想找到兩個數字的最大值,並打印出來。 我想打印所有三個數字。 我正在使用以下代碼。

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

}

但是,我收到兩個語法錯誤(請找到附圖)。 有人可以幫我解決嗎?

將輸出打印的行更改為:

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

請參閱此處的文檔

printf("\nmaximum of %d and %d is = %d",a,b,c);
#include <stdio.h>

int main () {
    int a = 1;
    int b = 2;
    int c = a + b;
    printf("The sum of %d and %d is %d", a, b, c);
    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM