Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C語言 圖形問題??

設計一程式,並能輸入5*5的\"等邊倒立三角形\"、\"等邊正立三角形\"、\"等邊菱形\"及\"等邊梯形\"。

2 Answers

Rating
  • Jeremy
    Lv 4
    2 decades ago
    Favorite Answer

    if you have any questions, please contact me.

    E-mail: tsungjung411@yahoo.com.tw

    ---------------------------------------------------------

    程式下載觀摩:

    http://home.kimo.com.tw/tsungjung411/download/java...

    #include <stdio.h>

    void upsideDownTriangle(int n) {

      int i, j, k;

      printf("等邊倒立三角形:\n");

      for (i = n, j = 0; i > 0; i--, j++) {

        for ( k = 0; k < j; k++) {

          printf(" ");

        }

        for ( k = 0; k < i; k++) {

          printf("* ");

        }

        printf("\n");

      }

      printf("\n");

    }

    void triangle(int n) {

      int i, j, k;

      printf("等邊正立三角形:\n");

      for (i = 1, j = n - 1; i <= n; i++, j--) {

        for ( k = 0; k < j; k++) {

          printf(" ");

        }

        for ( k = 0; k < i; k++) {

          printf("* ");

        }

        printf("\n");

      }

      printf("\n");

    }

    void rhomb(int n) {

      int i, j, k;

      printf("等邊菱形:\n");

      for (i = 1, j = n - 1; i <= n; i++, j--) {

        for ( k = 0; k < j; k++) {

          printf(" ");

        }

        for ( k = 0; k < i; k++) {

          printf("* ");

        }

        printf("\n");

      }

      for (i = n - 1, j = 1; i > 0; i--, j++) {

        for ( k = 0; k < j; k++) {

          printf(" ");

        }

        for ( k = 0; k < i; k++) {

          printf("* ");

        }

        printf("\n");

      }

      printf("\n");

    }

    void trapezium(int n) {

      int i, j, k;

      printf("等邊梯形:\n");

      for (i = 1, j = n - 1; i <= n; i++, j--) {

        for ( k = 0; k < j; k++) {

          printf(" ");

        }

        for ( k = 0; k < i + n - 1; k++) {

          printf("* ");

        }

        printf("\n");

      }

      printf("\n");

    }

    void main() {

      int n;

      printf("Please input aa positive integer n= ");

      scanf("%d", &n);

      upsideDownTriangle(n);

      triangle(n);

      rhomb(n);

      trapezium(n);

    }

    執行結果:

    Please input aa positive integer n= 5

    等邊倒立三角形:

    * * * * * 

     * * * * 

      * * * 

       * * 

        * 

    等邊正立三角形:

        * 

       * * 

      * * * 

     * * * * 

    * * * * * 

    等邊菱形:

        * 

       * * 

      * * * 

     * * * * 

    * * * * * 

     * * * * 

      * * * 

       * * 

        * 

    等邊菱形:

        * * * * * 

       * * * * * * 

      * * * * * * * 

     * * * * * * * * 

    * * * * * * * * * 

    Press any key to continue

    Source(s): me
  • 1 decade ago

    run不出來~~其中菱形有八個erorr(註:我不是用複製貼上的)

Still have questions? Get your answers by asking now.