<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C++ 程序:通過將結構傳遞給函數來相加復數 > 原文: [https://www.programiz.com/cpp-programming/examples/complex-number-add](https://www.programiz.com/cpp-programming/examples/complex-number-add) #### 該程序將兩個復數作為結構并通過使用函數將它們相加。 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ 結構](/cpp-programming/structure) * [C++ 結構和函數](/cpp-programming/structure-function) * * * * * * ## 示例:相加兩個復數的源代碼 ```cpp // Complex numbers are entered by the user #include <iostream> using namespace std; typedef struct complex { float real; float imag; } complexNumber; complexNumber addComplexNumbers(complex, complex); int main() { complexNumber n1, n2, temporaryNumber; char signOfImag; cout << "For 1st complex number," << endl; cout << "Enter real and imaginary parts respectively:" << endl; cin >> n1.real >> n1.imag; cout << endl << "For 2nd complex number," << endl; cout << "Enter real and imaginary parts respectively:" << endl; cin >> n2.real >> n2.imag; signOfImag = (temporaryNumber.imag > 0) ? '+' : '-'; temporaryNumber.imag = (temporaryNumber.imag > 0) ? temporaryNumber.imag : -temporaryNumber.imag; temporaryNumber = addComplexNumbers(n1, n2); cout << "Sum = " << temporaryNumber.real << temporaryNumber.imag << "i"; return 0; } complexNumber addComplexNumbers(complex n1,complex n2) { complex temp; temp.real = n1.real+n2.real; temp.imag = n1.imag+n2.imag; return(temp); } ``` **輸出** ```cpp Enter real and imaginary parts respectively: 3.4 5.5 For 2nd complex number, Enter real and imaginary parts respectively: -4.5 -9.5 Sum = -1.1-4i ``` 在問題中,用戶輸入的兩個復數存儲在結構`n1`和`n2`中。 這兩個結構傳遞給`addComplexNumbers()`函數,該函數計算總和并將結果返回給`main()`函數。 最后,通過`main()`函數顯示總和。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看