lundi 13 juin 2022

How to print V in c programming in 10X10 row and column in a optimized way?

I printed V using * in specific rows and columns. I had lots of if statements. I am sharing my code below.

Is there any optimised way to print the V pattern in 10X10 row column? (without many if conditions)?

#include<stdio.h>
int main() {
  int row, column;
  for (row = 1; row <= 10; row++) {
    for (column = 1; column <= 10; column++) {
      if (row == 1 && (column == 1 || column == 10)
          || row == 3 && (column == 2 || column == 9)
          || row == 5 && (column == 3 || column == 8)
          || row == 7 && (column == 4 || column == 7)
          || row == 10 && column == 5)
        printf("*");
      else
        printf(" ");

    }

    printf("\n");
  }
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire