|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/cs256su21code/jun21/cube.c
/*
Write a function named "cube" that takes one integer as an
argument and returns the cube of that number (also an integer).
Recall that the cube of a number is the same number multiplied by itself three times.
*/
#include <stdio.h>
int cube(int n); //function declaration
int main(){
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("The cube of %d is %d\n", num, cube(num)); //calling the function cube inside the printf statement
/*
we could also have written the above like this
int ans = cube(num); //calling cube and putting the answer in ans
printf("The cube of %d is %d\n", num, ans);
*/
return 0;
}
int cube(int n){
//returns the cube of a number
return n * n * n;
}
|