本题要求实现函数输出一个实心的字符矩形,定义并调用函数matrix(length, width, ch),它的功能是在屏幕上显示行数为width、列数为length,由字符ch组成的实心矩形图案。

其中length是矩阵的长度,width是矩阵的宽度,ch是输出的字符,要求函数按照如样例所示的格式,打印出行数为width、列数为length,由字符ch组成的实心矩形图案。

以下是实现函数matrix的C++代码:

#include <iostream>

using namespace std;

void matrix(int length, int width, char ch) {
    for (int i = 0; i < width; i++) { // 控制行数
        for (int j = 0; j < length; j++) { // 控制列数
            cout << ch;
        }
        cout << endl;
    }
}

int main() {
    matrix(5, 7, '*'); // 调用函数输出一个宽为5,高为7的由*组成的实心矩形
    return 0;
}

举例:函数调用matrix(5, 7, '*')将输出如下实心矩形:

*****
*****
*****
*****
*****
*****
*****

如果对你有帮助的话,请给我一个采纳,谢谢啦

#include <stdio.h>

void matrix(int length, int width, char ch) 
{
    int i, j;

    for (i = 1; i <= width; i++) {
        for (j = 1; j <= length; j++) {
            printf("%c", ch);
        }
        printf("\n");
    }
}

int main() 
{
    int length=5, width=7;
    char ch='*';
    matrix(length, width, ch);
    return 0;
}

运行结果

img