C Language Print various graphics

Source: Internet
Author: User

A variety of graphics can be printed in the C language using loops

1 Right triangle (upright on the right): part of the Code

  inti,j;  for(i=0; i<6; i++) {         for(j=6; j>i; j--.) {printf (" "); }         for(j=0; j<=i; J + +) {printf ("*"); } printf ("\ n"); }

Operating effect:

There are a variety of right triangle are not introduced.

2. Isosceles triangle (Upright) Part of the code is as follows:

    int i,j;    For (i=0, i<6; i++) {for        (j=6; j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1;j++) {            printf ("*");        }        printf ("\ n");    }

The results are as follows:

Inverted isosceles triangle:

    int i,j;    For (i=0, i<6; i++) {for        (j=0; j<i; J + +) {            printf ("");        }        for (j=0; j<11-2*i;j++) {            printf ("*");        }                printf ("\ n");      }

Operating effect:

3. Diamond

Code:

    int i,j,k;    for (i=1;i<=5;i++) {for        (j=6;j>i;j--) {            printf ("");        }        for (k=1;k<=2*i-1;k++) {            printf ("*");        }        printf ("\ n");    }    for (i=1;i<=6;i++) {for            (j=1;j<=i-1;j++) {                printf ("");            }            for (k=1;k<=13-2*i;k++) {                printf ("*");            }            printf ("\ n");            }

Operating effect:

4. Hollow Triangles

Code:

    int i,j;    For (i=0, i<5; i++) {for        (j=5; j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1;j++) {            if (j==0| | j==2*i| | i==0| | i==4) {                printf ("*");            } else{                printf ("");            }                 }        printf ("\ n");    }

Effect:

5. Hollow Diamond: The principle and the principle of the hollow triangle is similar

The code is as follows:

    int i,j;    For (i=0, i<4; i++) {for        (j=3;j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1; J + +) {                        if (j==0| | J==2*i) {                printf ("*");            } else{                printf ("");            }        }        printf ("\ n");    }        For (i=0, i<4; i++) {for        (j=0; j<i; J + +) {            printf ("");        }        for (j=0;j<7-2*i; J + +) {            if (j==0| | J==6-2*i) {                printf ("*");            } else {                printf ("");            }        }        printf ("\ n");    }

Effect:

6, Pine

The code is as follows:

    Christmas??    int i,j;    For (i=0, i<3; i++) {for        (j=4;j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1; J + +) {            printf ("*");        }        printf ("\ n");    }    For (i=0, i<4; i++) {for        (j=4; j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1; J + +) {            printf ("*");        }        printf ("\ n");    }    For (i=0, i<5; i++) {for        (j=4; j>i; j--) {            printf ("");        }        for (j=0; j<2*i+1; J + +) {            printf ("*");        }        printf ("\ n");    }    For (i=0, i<5; i++) {for        (j=0;j<3;j++) {            printf ("");        }        for (j=0; j<3;j++) {            printf ("*");        }        printf ("\ n");    }    For (i=0, i<2; i++) {for        (j=0; j<10; J + +) {            printf ("*");        }        printf ("\ n");    }

Effect:

C Language Print various graphics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.