In C, use the stream operator >> to input two numbers. The steps are as follows: Declare two variables num1 and num2. Use the cin stream object and the >> operator to read data from standard input and store it in a variable: cin >> num1 >> num2 . Sample code: #include
int main() { int num1, num2; std::cout << "Please enter two numbers, separated by spaces:"; std::cin &
In C, you can use the stream operator> ;> to enter two numbers. The following are the steps to enter two numbers: </p>
<h3>1. Declare two variables</h3>
<p>First, you need to declare two variables to store the entered numbers: </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>int num1;
int num2;</pre><div class="contentsignin">Copy after login</div></div><h3>2. Use <code>cin
Input
Using the cin
stream object, data can be read from standard input. Operator is used to store user-entered data into variables.
cin >> num1 >> num2;
The following is a complete sample code that demonstrates how to enter two numbers:
#includeint main() { int num1; int num2; std::cout << "请输入两个数字,用空格隔开:"; std::cin >> num1 >> num2; std::cout << "输入的两个数字是:" << num1 << ", " << num2 << std::endl; return 0; }
cin
reads data from standard input, so make sure the user enters two numbers at the prompt. The above is the detailed content of How to input two numbers in c++. For more information, please follow other related articles on the PHP Chinese website!