Ask Question

Write a C program that includes a function of type double called divemaster accepts two double arguments (you must write the divemaster function). When called, your function will return the first argument divided by the second argument. Make sure your function includes a decision statement so that it can't divide by 0--if the caller attempts to divide by 0 the function should return a value of - 1.0.

+4
Answers (1)
  1. 1 July, 07:20
    0
    Following is the C program to divide two numbers:

    #include

    double divemaster (double first, double second)

    {

    //Check if second argument is zero or not

    if (second!=0)

    return first/second;

    else

    return - 1.0;

    }

    int main ()

    {

    printf ("%f/n", divemaster (100,20));

    printf ("%f/n", divemaster (100,0));

    }

    Output:

    5.000000

    -1.000000

    Explanation:

    In the above program, a function divemaster is declared which divedes the first argument with second and return the result.

    Within the body of divemaster function if else block is used to verify that the second argument is not zero, and thus there is no chance of divide by zero error.

    In main two printf statements are used to call the divemaster function. One to check normal division process and second to check divide by zero condition.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a C program that includes a function of type double called divemaster accepts two double arguments (you must write the divemaster ...” 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