当前位置:网站首页>Print rows and columns according to the specified characters

Print rows and columns according to the specified characters

2020-12-06 20:48:23 Piglets need to learn programming

#pragma warning(disable:4996)
#include<stdio.h>
void display(char cr, int lines, int width) {    // Definition display function 
	int row, col;
	for (row = 1; row <= lines; row++) {
		for (col = 1; col <= width; col++)
			putchar(cr);
		putchar('\n');
	}
}
void display(char cr, int lines, int width);
int main() {

	int ch;               // Characters to be printed 
	int rows, cols;       // Number of rows and columns 
	printf("Enter a character and two integers:\n");
	while (ch = getchar() != '\n') {
		if (scanf("%d %d", &rows, &cols) != 2)
			break;
		display(ch, rows, cols);
		while (getchar() != '\n')
			continue;
		printf("Enter another character and two integers;\n");
		printf("Enter a newline to quit.\n");
	}
	printf("Bye.\n");
	return 0;
}

版权声明
本文为[Piglets need to learn programming]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012062039210435.html