Advertisement
freakshow

chapter 4, project 1 - mycube

Jul 22nd, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /*
  2. * Chapter 4, Project 1; cubit.c
  3. * Author: blah
  4. * Description: Write a function called mycube which receives an int argument returning
  5. * the cube of the received int.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <math.h>
  10.  
  11. int mycube(int ii) { //the function does the heavy lifting only, no talking
  12. int xx; //initialize a local scope variable
  13. xx = ii * ii * ii; //work the math
  14. return xx; //return a result to the caller
  15. }
  16.  
  17. int main(void) {
  18.  
  19. // int input, cubed; //initialize variables for main
  20.  
  21. int xx, yy, zz;
  22. xx = 2;
  23.  
  24. yy = mycube(xx);
  25.  
  26. zz = mycube(mycube(mycube(mycube(xx))));
  27.  
  28. printf("The value of xx is %d, yy is %d and zz is %d \n", xx, yy, zz);
  29.  
  30. // printf("Please enter an int to cube: "); //ask for input
  31. // scanf("%d", &input); //drop the input into the memory address for target
  32.  
  33. /*pass the value of variable 'input' as the argument to function 'mycube', assign the return
  34. to the local scope variable.*/
  35. // cubed = mycube(input);
  36.  
  37. //output the user input and the result.
  38. // printf("The cube for %d is %d.\n", input, cubed);
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement