Double for statement

Asked 2 years ago, Updated 2 years ago, 98 views

Please tell me how to write a code that allows a pentagon to come out upside down by taking a double for moon *

c for

2022-09-20 16:34

1 Answers

If you just print it out, you do this.

#include <stdio.h>
int main() {
    printf("\n");
    //upper part
    for (int i=3; i <= 4; i++) {
        for (int j=0; j < 6 - i; j++) {
            printf(" ");
        }
        for (int j=0; j < i * 2 + 1; j++) {
            printf("*");
        }
        printf("\n");
    }
    //Lower part
    for (int i=1; i <= 6; i++) {
        for (int j=0; j < i; j++) {
            printf(" ");
        }
        for (int j=0; j < (6 - i) * 2 + 1; j++) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}


2022-09-20 16:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.