Write a program that prints a staircase of size n.
I did not pass through all the test cases and don't understand where I made mistake.
This is my code:
void staircase(int n) {
char a[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if((i + j) > ((n / 2) + 1)) {
a[i][j] = '#';
printf("%c", a[i][j]);
} else {
printf(" ");
}
}
printf("\n");
}
}
Sample Input
6
Sample Output
#
##
###
####
#####
######
Explanation:
The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n=6
.
Aucun commentaire:
Enregistrer un commentaire