Holey_yan

20140304_KUAS_VisualC++_TernaryOperator

Mar 4th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. /************************************/
  2. /** 20140304 Ternary Operator      **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2014/03/04 am.00:14   **/
  6. /************************************/
  7.  
  8. //引入標頭檔
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. /*此程式是一比較兩數的範例
  13.   由使用者輸入兩數字, 判斷何者為大並輸出*/
  14. void main()
  15. {
  16.     //定義兩變數
  17.     int number_1, number_2;
  18.      
  19.     //----------輸入兩數字----------
  20.     printf("number_1 = ");
  21.     scanf("%d", &number_1);
  22.  
  23.     printf("number_2 = ");
  24.     scanf("%d", &number_2);
  25.     //------------------------------
  26.  
  27.     /*Ternary Operator(三元運算子) 使用格式為
  28.     -------------------------------------------
  29.       ([條件運算子] ? [Ture] : [False])
  30.     -------------------------------------------*/
  31.     printf("%d is bigger.\n", (number_1 > number_2 ? number_1 : number_2));
  32.  
  33.     system("pause");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment