⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch04.03.c

📁 C++Primer中文版 第三版 深入系列 Primer 第三版 著 中中文文版版潘爱民张丽译 Addison-Wesley 中国电力出版社 www.infopower.com.cn S
💻 C
字号:
// #include <iostream>
#include <iostream.h>

/*****
  The larger value of 10 and 20 is 20
  The value of 10 is even.
  The larger value of 10, 20 and 30 is 30
*****/

int main()
{
    int i = 10, j = 20, k = 30;

    cout << "The larger value of "
         << i << " and " << j << " is "
         << ( i > j ? i : j ) << endl;

    cout << "The value of " << i << " is"
         << ( i % 2  ? " odd." : " even." )
         << endl;

    /* the conditional operator can be nested,
     * but a deep nesting is difficult to read
     * in this example,
     * max is set to the largest of 3 variables
     */

    int max = ( (i > j)
        ? (( i > k) ? i : k)
        : ( j > k ) ? j : k);

    cout << "The larger value of "
         << i << ", " << j << " and " << k
         << " is " << max << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -