Ask Question

Write the definition of a function named max that receives an int parameter and returns the largest value that it has been called with so far. So, if you make these calls to max, max (5), max (3), max (12), max (4), the values returned will be (respectively) : 5, 5, 12, and 12.

+2
Answers (1)
  1. 23 March, 13:22
    0
    Following are the code in the C language.

    int max (int x) / / function definition

    {

    static int largest=0; / / variable declaration

    if (x>largest) / / checking the condition

    largest=x; / / assign the value of input in the largest variable

    return largest; / / return the largest number

    }

    Explanation:

    Following are the description of code.

    Decalred a function max of int type which hold a parameter x of int datatype. In this function compared the number x with the largest. If this condition is true then largest number hold the value of x variable Finally return the largest number.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the definition of a function named max that receives an int parameter and returns the largest value that it has been called with so ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers