|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/h5/squareAndCube.c
/*
squareAndCube.c
This program currently has one function, "square" that returns the
square of a number.
Your task is to add another function named "cube", that returns the cube
of a number.
This new function will be set up nearly identical to the square
function, the only difference is what the function returns.
Reminder:
square: x * x
cube : x * x * x
*/
#include <stdio.h>
int square(int); //function prototype for the square function
// write the function prototype for the "cube" function here
// this will be written in the same format as above
int main(){
int n; //variable declaration for the number
//ask user for a number
printf("Enter a number:> ");
scanf("%d", &n);
//then print out the number
printf("%d squared is %d\n", n, square(n));
/*
print the cube of the number the same way you're printing out
the square of a number
*/
return 0;
}
//definition of the square function is here
int square(int x){
return x*x; //just return x * x,
}
//you will define the cube function down here
//you set it up like the function above, the only difference between square and
//cube will be the return statement.
|