Cross (X) Pattern
C
Medium
3 views
Problem Description
* *
* *
* *
* *
*
* *
* *
* *
* *
Main diagonal and anti-diagonal stars. Condition: i==j OR i+j==n-1
Official Solution
#include <stdio.h>
int main() {
int n = 5; // middle row number
int size = 2*n - 1; // total rows/columns
int i, j;
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
if (i == j || i + j == size - 1)
printf("*");
else
printf(" ");
}
printf("n");
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!