vendredi 9 mars 2018

Print an inverse Z pattern

How to print an inverse Z pattern?

Code for a normal Z pattern:

int main() {

int n;

printf("Enter number of rows: ");
scanf("%d", &n);

for (int row = 0; row < n; row++) {
    for (int column = 0; column < n; column++) {
        if (row == 0 || row == n - 1 || column == n - 1 - row) {
            printf("* ");
        }
        else {
            printf("  ");
        }
    }
    printf("\n");
}
return 0;
}

Output for the code above for n = 5:

* * * * *
      * 
    *  
  *
* * * * *

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire