Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140408 Exam 07 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/04/08 am.11:45 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- /*先行定義函式(function)
- 定義函式使用格式為
- ----------------------------------------------
- 函式型態(參數型態1, 參數型態2, 參數型態3, ...)
- ----------------------------------------------
- 若是省略下列兩行先行定義,則必須將使用之函數挪至main 之前*/
- void _1(int, int);
- void _2(int, int);
- void main()
- {
- printf("Enter a number: ");
- int input = 1;
- scanf("%d", &input);
- for(int i = 1; i <= input * 2; i ++)
- {
- if(i <= input)
- {
- //呼叫函數_1,並在內導入參數i 與input
- _1(i, input);
- }
- else
- {
- if(i != input + 1)
- {
- //呼叫函數_2,並在內導入參數i 與input
- _2(i, input);
- }
- }
- }
- system("pause");
- }
- /*函數一
- 函數使用格式為
- -------------------------------------------------------------------
- 先前定義之型態與名稱(參數型態1 參數名稱1, 參數型態2 參數名稱2, ...)
- -------------------------------------------------------------------*/
- void _1(int i, int input)
- {
- for(int j = 2; j <= i; j++)
- {
- printf(" ");
- }
- printf("*");
- for(int j = 1; j <= input - i; j++)
- {
- printf("**");
- }
- printf("\n");
- return; //此行在本程式可省略不打
- }
- /*函數二
- 函數使用格式為
- -------------------------------------------------------------------
- 先前定義之型態與名稱(參數型態1 參數名稱1, 參數型態2 參數名稱2, ...)
- -------------------------------------------------------------------*/
- void _2(int i, int input)
- {
- for(int j = 1; j <= input * 2 - i; j++)
- {
- printf(" ");
- }
- printf("*");
- for(int j = 2; j <= i - input; j++)
- {
- printf("**");
- }
- printf("\n");
- return; //此行在本程式可省略不打
- }
Advertisement
Add Comment
Please, Sign In to add comment