Holey_yan

20140408_KUAS_VisualC++_Exam07

Apr 8th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. /************************************/
  2. /** 20140408 Exam 07               **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2014/04/08 am.11:45   **/
  6. /************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /*先行定義函式(function)
  12.   定義函式使用格式為
  13.   ----------------------------------------------
  14.   函式型態(參數型態1, 參數型態2, 參數型態3, ...)
  15.   ----------------------------------------------
  16.   若是省略下列兩行先行定義,則必須將使用之函數挪至main 之前*/
  17. void _1(int, int);
  18. void _2(int, int);
  19.  
  20.  
  21. void main()
  22. {
  23.     printf("Enter a number: ");
  24.     int input = 1;
  25.     scanf("%d", &input);
  26.  
  27.     for(int i = 1; i <= input * 2; i ++)
  28.     {
  29.         if(i <= input)
  30.         {
  31.             //呼叫函數_1,並在內導入參數i 與input
  32.             _1(i, input);
  33.         }
  34.         else
  35.         {
  36.             if(i != input + 1)
  37.             {
  38.                 //呼叫函數_2,並在內導入參數i 與input
  39.                 _2(i, input);
  40.             }
  41.         }
  42.     }
  43. system("pause");
  44. }
  45.  
  46. /*函數一
  47.   函數使用格式為
  48.   -------------------------------------------------------------------
  49.   先前定義之型態與名稱(參數型態1 參數名稱1, 參數型態2 參數名稱2, ...)
  50.   -------------------------------------------------------------------*/
  51. void _1(int i, int input)
  52. {
  53.     for(int j = 2; j <= i; j++)
  54.     {
  55.         printf(" ");
  56.     }
  57.     printf("*");
  58.     for(int j = 1; j <= input - i; j++)
  59.     {
  60.         printf("**");
  61.     }
  62.     printf("\n");
  63.    
  64.     return; //此行在本程式可省略不打
  65. }
  66.  
  67. /*函數二
  68.   函數使用格式為
  69.   -------------------------------------------------------------------
  70.   先前定義之型態與名稱(參數型態1 參數名稱1, 參數型態2 參數名稱2, ...)
  71.   -------------------------------------------------------------------*/
  72. void _2(int i, int input)
  73. {
  74.     for(int j = 1; j <= input * 2 - i; j++)
  75.     {
  76.         printf(" ");
  77.     }
  78.     printf("*");
  79.     for(int j = 2; j <= i - input; j++)
  80.     {
  81.         printf("**");
  82.     }
  83.     printf("\n");
  84.  
  85.     return; //此行在本程式可省略不打
  86. }
Advertisement
Add Comment
Please, Sign In to add comment