#include<stdio.h>
void display(char cr, int lines, int width);
int main()
{
char c;
int rows, cols;
while (1) {
scanf("%c %d %d", &c, &rows, &cols);
while (getchar() != '\n') continue;
display(c, rows, cols);
if (c == '\n')
break;
}
return 0;
}
void display(char cr, int lines, int width) {
int a = 0, b = 0;
while (a < lines) {
while (b < width) {
printf("%c", cr);
b++;
}
printf("\n");
a++;
b = 0;
}
}
while (1) {
scanf("%c %d %d", &c, &rows, &cols);
while (getchar() != '\n') continue;
display(c, rows, cols);
if (c == '\n')
break;
}
문자와 행,열을 순서대로 입력받고
입력받은 문자이후에 공백이 있더라도 전부 읽고 버퍼에서 없애준다.
display함수를 호출하고,
c값이 만약 줄바꿈이라면 무한루프를 탈출한다.
void display(char cr, int lines, int width) {
int a = 0, b = 0;
while (a < lines) {
while (b < width) {
printf("%c", cr);
b++;
}
printf("\n");
a++;
b = 0;
}
}
입력 받은 문자와 행,열만큼 문자를 출력해주는 함수이다.
결과값 출력
a가 2개씩 5줄로 출력되었다.