The following method can be used to output multiple results in C: use the comma operator (,) to output the expression results one by one and separate them with spaces. Use the insertion operator (<<) and a stream object to insert multiple values into cout one after another for output. Use the printf function to output multiple results in a single function call using format specifiers.
How to output multiple results in C
To output multiple results in C, you can use the following method Implementation:
1. Use the comma operator (,)
The comma operator is used to connect multiple expressions and execute them in order. On output, the results of each expression are displayed separated by spaces. For example:
cout << "结果 1: " << 10 << ", 结果 2: " << 20 << endl;
Output:
结果 1: 10, 结果 2: 20
2. Use the insertion operator (<<) and the stream object
insertion operator (< ;<) You can insert values into stream objects, such ascout
. Multiple results can be output by inserting multiple values intocout
. For example:
cout << "结果 1: " << 10 << " 结果 2: " << 20 << endl;
Output:
结果 1: 10 结果 2: 20
3. Use theprintf
function
printf
function to Format and output variables. By using format specifiers, you can output multiple results in a single function call. For example:
printf("结果 1: %d, 结果 2: %d\n", 10, 20);
Output:
结果 1: 10, 结果 2: 20
Note:When using these methods, make sure the text or delimiters between the individual results are correct to provide clarity and ease of understanding Output.
The above is the detailed content of How to output two results in c++. For more information, please follow other related articles on the PHP Chinese website!