#include <stdio.h>
// Define a function that takes an integer as an argument and returns its square
int square(int x) {
return x * x;
}
// Define a function that takes an integer as an argument and returns its cube
int cube(int x) {
// Call the square function within the cube function
int x_squared = square(x);
return x_squared * x;
}
int main(void) {
// Call the cube function and print the result
int result = cube(3);
printf("The cube of 3 is %d\n", result);
return 0;
}
This program defines two functions: square
, which takes an integer as an argument and returns its square, and cube
, which takes an integer as an argument and returns its cube. The cube
function calls the square
function to calculate the square of the input value before calculating the cube.
Here is an example of the output of this program:
The cube of 3 is 27
0 Comments