4.7k views
4 votes
Practice problems on functions. Write C function(s) to carry out the specified tasks. For each problem, also write the suggested application program(s) that apply the function. (1) Write a function multiPrint(int n, char c) that prints n copies of a character c.

1 Answer

7 votes

Answer:

Function:

int fun(int n,char c) // function definition with a two argument in which variable n is a integer type and variable c is a character type.

{

while(n>0)// while loop

{

printf("%c",c); // print statement for character

n--; // decrease statement to false the loop.

}

return 0; //return statement.

}

output:

  • When the user pass n=5 and c='a', it will prints 5 times 'a' character.
  • When the user passes n=10 and c='t', it will print 10 times 't' character.

Step-by-step explanation:

  • Firstly we declare a function of two arguments in which variable n is an integer type and variable c is a character type.
  • Then in the function body, we use while loop from n times iteration because question demands to print n time any character.
  • Then in the loop body, we use a print statement to print a character and a decrease statement to false the loop after a finite iteration.
User Farkie
by
5.6k points