Design, code, and test a program that includes a function of type double called divbaby that accepts two double arguments (you must write the divbaby 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 -2.0. Your program should call divbaby then display the value returned by the function. Test your function thoroughly then submit output using the arguments 45.7 and 21.3. Remember that a structured function will have have only one return statement.
in a c program please.
C code:
#include <stdio.h>
//initializing divbaby function
double divbaby(double num1,double num2){
//checking if the second number is 0
if(num2==0)
//returning -2.0
return -2.0;
else
//returning num1 divided by num2
return num1/num2;
}
int main()
{
//calling divbaby function and printing the result for sample
value
printf("%lf",divbaby(45.7,21.3));
return 0;
}
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.