Ask Question
18 March, 16:08

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.

+2
Answers (1)
  1. 18 March, 19:59
    0
    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.

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Practice problems on functions. Write C function (s) to carry out the specified tasks. For each problem, also write the suggested ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers