Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Chapter 4, Project 1; cubit.c
- * Author: blah
- * Description: Write a function called mycube which receives an int argument returning
- * the cube of the received int.
- */
- #include <stdio.h>
- #include <math.h>
- int mycube(int ii) { //the function does the heavy lifting only, no talking
- int xx; //initialize a local scope variable
- xx = ii * ii * ii; //work the math
- return xx; //return a result to the caller
- }
- int main(void) {
- // int input, cubed; //initialize variables for main
- int xx, yy, zz;
- xx = 2;
- yy = mycube(xx);
- zz = mycube(mycube(mycube(mycube(xx))));
- printf("The value of xx is %d, yy is %d and zz is %d \n", xx, yy, zz);
- // printf("Please enter an int to cube: "); //ask for input
- // scanf("%d", &input); //drop the input into the memory address for target
- /*pass the value of variable 'input' as the argument to function 'mycube', assign the return
- to the local scope variable.*/
- // cubed = mycube(input);
- //output the user input and the result.
- // printf("The cube for %d is %d.\n", input, cubed);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement