1 like 0 dislike
915 views
請設計一個程式,利用迴圈輸出文字菱形。

p.s. 輸入皆為奇數

範例輸入1:

5

範例輸出1:

  *

 ***

*****

 ***

  *
[Exercise] Coding (C) - asked in 2016-1 程式設計(一)AC by (18k points)
ID: 15388 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00

reshown by | 915 views
0 2
Called for Help
0 0
#include <stdio.h>
#include <stdlib.h>

int main()

{
    int a,n,m,k;
    scanf("%d",&a);
    for(n=1;n<=a;n=n+2)
    {
        for(k=(a-n)/2;k>0;k--)
        {
            printf(" ");
        }
        for(m=1;m<=n;m=m+1)
        {
            printf("*");
        }
        printf("\n");
    }
    for(n=a-2;n>0;n=n-2)
    {
        for(k=(a-n)/2;k>0;k--)
        {
            printf(" ");
        }
        for(m=1;m<=n;m=m+1)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

42 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()

{
* * * * ** ** * **** num,i,j;
* * * **** * *** * *** *** * * ** ** *
*** ** ** * (j=1; j<=num/2+1; j++)
* * * *** *** * *** ***
* * ** * ***** *** * ** * (i=0; i<num/2+1-j; i++)
* * * ** **** ** ** * * * ** *** * * ** *** * ** ");
* ******* * * *** * *** ** * ** (i=0; i<(j-1)*2+1; i++)
* *** * * ** **** * ***** * *** * ** ** * *** * ** * ** * * **
** * *** *** *** * * ** *** *** * ** ** *
**** * ** * * * ** **
***** **** * ** **** (j=num-(num/2+1); j>0; j--)
* ** * * **** ** *** *
* ** * * ****** ** * * * ** ** *** ** (i=0; i<num/2+1-j; i++)
** * ** *** ** * * * ** ** * ** *** *** ** *** * ");
** * * ** * * **** * * * *** ***** * (i=0; i<(j-1)*2+1; i++)
*** *** *** ***** * * * * * * * * * * * * **** * *** * *
* ** ** * * ** * * * * * * ** ** * * *
*** *** * *****

}
answered by (-162 points)
0 like 0 dislike
Hidden content!
* * ** ****



int main()

{
* ** * **** ** *** *** * n, j, k;


* ** **** *** * * ** * ** ** * , &n);
** *** *** ** * ** * = 1; j <= n / 2 + 1;j ++)
* * ** * * ** * ** *
* *** ** ** *** * * ** ** * * * * * * = 0;k < n / 2 + 1 - j;k ++)
** ** ** * * *** * * ** ** ** *** ** ");
* * **** * ** * * *** * * **** * ******* < (j-1) * 2 + 1;k ++)
* ** * *** ** * ** ** * ******* * ** * *** *** ** *
* ** * * ** ** ** *** * * * ** * * * * * * ** * *
***** *** ***
* * * * *** * **** = n - (n / 2 + 1); j >= 0;j --)
** **** * **
* * ** * * **** * ** * ** *** *** * * = 0;k < n / 2 + 1 - j;k ++)
**** * ** * ** * ****** * * *** * * * ** * * * * *** ");
**** ** *** *** ******** * **** * ** ******** *** < (j-1) * 2 + 1;k ++)
** * ** * * * **** * ** * ** ***** *** *** **** *
** *** * * ** * * * ** ** ******** **** * **** * * **
* ** ** **** * **
*** ** ** * ** * 0;

}
answered by (-114 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.58.97
©2016-2024

Related questions

0 like 0 dislike
0 answers
[Resource] asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15475 - Available when: Unlimited - Due to: Unlimited
| 13 views
0 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15447 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 238 views
1 like 0 dislike
37 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15446 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 630 views
1 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15442 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 412 views
1 like 0 dislike
18 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15440 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 417 views
12,783 questions
183,443 answers
172,219 comments
4,824 users