C primer plus 第六版 第九章 第二题 编程练习答案

版权声明:转载请注明来源~ https://blog.csdn.net/Lth_1571138383/article/details/80536047

Github 地址:这里这里φ(>ω<*)

/*

     本程序应 习题 2 建立。
   题目要求: 设计一个函数chline(ch,i,j),打印指定的字符j行i列。
                在一个简单的驱动程序中测试该函数。
*/


#include<stdio.h>


void chline(char ch, int i, int j);


int main(void)
{
char c = 0;
int line = 0;
int column = 0;


printf("输入待打印字符,及行数与列数。(按顺序输入,每输入一个数以回车键结束) :");


c = getchar();
getchar();
scanf_s("%d %d", &line, &column);


chline(c, column, line);


getchar();
getchar();


return 0;
}


void chline(char ch, int i, int j)
{
int y = 0;
int t = 0;


for (y = 0; y < j; y++)
{
for (t = 0; t < i; t++)
{
putchar(ch);
}


putchar('\n');
}


putchar('\n');
printf("Bye ! \n");


return;
}

猜你喜欢

转载自blog.csdn.net/Lth_1571138383/article/details/80536047