fork download
  1. // C code
  2. // This program will provide options for a user to calculate the square
  3. // or cube of a positive Integer input by a user.
  4. // Developer: Jose Briscoe CMIS102
  5. // Date: February 25, 2017
  6.  
  7. #include <stdio.h>
  8.  
  9. // Function prototypes
  10. int Shrink(int value);
  11.  
  12.  
  13. int main ()
  14. {
  15. /* variable definition: */
  16. int intValue;
  17. double Results;
  18. intValue = 1;
  19.  
  20. // While a positive number
  21.  
  22. do {
  23. printf ("Enter a positive Integer\n: ");
  24. scanf("%d", &intValue);
  25. }
  26.  
  27. while (intValue > 0);
  28.  
  29.  
  30. if (intValue > 0)
  31. {
  32. // Call the Shrink Function
  33. Results = Shrink(intValue);
  34. printf("integer %d divided by 2 is %.2f\n",intValue,Results);
  35.  
  36. } //Close If
  37.  
  38. else
  39. printf("Only will divide by positive integers\n");
  40.  
  41. return 0;
  42.  
  43. } //Close Main
  44.  
  45.  
  46. /* function that would take an Integer and return the Integer divided by 2 */
  47. int Shrink(int value)
  48. {
  49. return value/2;
  50. }
  51.  
Success #stdin #stdout 0s 10304KB
stdin
9
24
-27
stdout
Enter a positive Integer
: Enter a positive Integer
: Enter a positive Integer
: Only will divide by positive integers