132k views
4 votes
Write a function definition that has three integers (a, b, c) declared within the function. It should return the value of c minus a times the value of b. Also, write the function prototype and the function call as it would appear in main.

User Oxwilder
by
4.4k points

1 Answer

3 votes

Answer:

#include <stdio.h>

// function prototype

int calculate(int, int, int);

int main()

{

// function call

printf("%d", calculate(2, 3, 5));

return 0;

}

// function definition

int calculate(int a, int b, int c){

return c - (a*b);

}

Step-by-step explanation:

Please see the comments in the code for each part.

The function definition is basically writing the function:

Write the type, name and parameters. Then, inside the curly braces, write what you want the function to do.

Create an int type function named calculate that takes three integers int a, int b, int c

Inside the function return the c - (a*b)

The function prototype is used to state that there will be such a function:

Write the return type, name, and parameters of the function and end with semicolon

The function call:

Writing the name and parameters of the function in the main. It allows us to execute the function. Note that above example, I call the function inside the printf statement so that the result can be displayed.

User Adp
by
5.2k points