use C program Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes use of this function.
时间: 2024-02-27 18:59:15 浏览: 181
Sure, I can help you with that. Here's the C program that defines the function you requested:
```c
#include <stdio.h>
void printChar(char c, int numChars, int numLines) {
for (int i = 0; i < numLines; i++) {
for (int j = 0; j < numChars; j++) {
printf("%c", c);
}
printf("\n");
}
}
int main() {
char c = '*';
int numChars = 5;
int numLines = 3;
printChar(c, numChars, numLines);
return 0;
}
```
This program defines a function called `printChar` that takes three arguments: a character `c`, an integer `numChars`, and an integer `numLines`. The function uses two nested loops to print the character `c` `numChars` times on each line, and repeats this process `numLines` times to print multiple lines.
In the `main` function, I've defined some sample values for the `char`, `numChars`, and `numLines` arguments, and called the `printChar` function with these values. You can modify these values to test the function with different inputs.
阅读全文