Printing the root sign in C: 1. Include the header file
; 2. Declare the double type variable number; 3. Enter the number into number; 4. Calculate the square root and store it in squareRoot; 5 . Print "The square root is:" squareRoot.
Printing the root sign in C
How to print the root sign?
In C, you can use the sqrt()
function to calculate the square root and print the result to the console. The radical symbol itself cannot be printed directly.
Detailed description:
Declare variables:
<code class="cpp">double number;</code>
Read user input:
<code class="cpp">cout << "输入一个数字:"; cin >> number;</code>
Calculate the square root:
<code class="cpp">double squareRoot = sqrt(number);</code>
Print the square root:
<code class="cpp">cout << "平方根为:" << squareRoot << endl;</code>
Example code :
<code class="cpp">#include <cmath> #include <iostream> using namespace std; int main() { double number; cout << "输入一个数字:"; cin >> number; double squareRoot = sqrt(number); cout << "平方根为:" << squareRoot << endl; return 0; }</code>
Run the example:
<code>输入一个数字:9 平方根为:3</code>
The above is the detailed content of How to type the root sign in c++. For more information, please follow other related articles on the PHP Chinese website!