Write a function that accepts a character ch and a number n as arguments. The function then displays an n x n grid filled with ch. Use the function in a program.
#include <stdio.h>
#include <stddef.h>
void display(char ch, size_t n) {
for (size_t i = 0; i != n; i++) {
for (size_t j = 0; j != n; j++) {
printf("%c", ch);
}
printf("\n");
}
}
int main() {
display('1', 5);
display('x', 4);
display('~', 3);
display('!', 2);
display('*', 1);
return 0;
}
Comments
Leave a comment