嘿伙计们,我正在努力学习我的课程。它应该打印出这样的梯形:
ccc
cccc
ccccc
cccccc
这就是我提出的:
int main() {
int n, m, row, column;
char c;
printf("Enter a character: ");
scanf("%c", & c);
printf("Enter number of rows\n");
scanf("%d", & n);
printf("Enter number of columns\n");
scanf("%d", & m);
for (row = 1; row <= n; row++) {
for (column = 1; column <= m; column++) {
printf("%c", c);
}
printf("\n");
}
return 0;
}
参数c = c
,n = 4
,m = 3
打印:
ccc
ccc
ccc
ccc
答案 0 :(得分:1)
您永远不会更改每行的宽度。尝试递增m
,如下所示:
int main(){
int n,m,row,column;
char c;
printf("Enter a character: ");
scanf("%c",&c);
printf("Enter number of rows\n");
scanf("%d",&n);
printf("Enter number of columns\n");
scanf("%d",&m);
for ( row = 1 ; row <= n ; row++ )
{
for( column = 1 ; column <= m ; column++ ){
printf("%c",c);
}
printf("\n");
m++; // this is the missing component!
}
return 0;
}
输出(使用您指定的设置c = 'c', n = 4, m = 3
):
ccc
cccc
ccccc
cccccc