gpt4 book ai didi

c - printf 相当于 cout 语句(字符串和同一语句中的多个变量)

转载 作者:行者123 更新时间:2023-11-30 21:23:01 25 4
gpt4 key购买 nike

我正在寻找与此 C++ 输出语句 (cout) 等效的 printf (C):

cout << "Indices and values: " << i << " " << j << ":" <<A_ii <<" "<< A_jj << endl;

这里ij是整数,A_iiAjj是小数。目前,我正在尝试此操作,但它似乎没有在 C 中提供所需的输出。

printf("\n索引和值:%d 和 %d : %d %d", i, j, A_ii, A_jj);

我在这里做错了什么?

最佳答案

你几乎是对的,你只是使用 int %d 格式标记作为你的小数。请尝试使用 %f

printf("\nIndices and values: %d and %d : %f %f", i, j, A_ii, A_jj);

关于c - printf 相当于 cout 语句(字符串和同一语句中的多个变量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49018047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com