fork download
  1. #include <stdio.h>
  2.  
  3. int Square(int value);
  4. int Cube(int value);
  5. int main ()
  6.  
  7. {
  8.  
  9. /* variable definition: */
  10.  
  11. int intValue, menuSelect,Results;
  12.  
  13. intValue = 1;
  14.  
  15. // While a positive number
  16.  
  17. while (intValue > 0)
  18.  
  19. {
  20.  
  21. printf ("Enter a positive Integer\n: ");
  22.  
  23. scanf("%d", &intValue);
  24.  
  25. if (intValue > 0)
  26.  
  27. {
  28.  
  29. printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: ");
  30.  
  31. scanf("%d", &menuSelect);
  32.  
  33. if (menuSelect == 1)
  34.  
  35. {
  36.  
  37. // Call the Square Function
  38.  
  39. Results = Square(intValue);
  40.  
  41. printf("Square of %d is %d\n",intValue,Results);
  42.  
  43. }
  44.  
  45. else if (menuSelect == 2)
  46.  
  47. {
  48.  
  49. // Call the Cube function
  50.  
  51. Results = Cube(intValue);
  52.  
  53. printf("Cube of %d is %d\n",intValue,Results);
  54.  
  55. }
  56.  
  57. else
  58.  
  59. printf("Invalid menu item, only 1 or 2 is accepted\n");
  60.  
  61. }
  62.  
  63. }
  64.  
  65. return 0;
  66.  
  67. }
  68.  
  69. /* function returning the Square of a number */
  70.  
  71. int Square(int value)
  72.  
  73. {
  74.  
  75. return value*value;
  76.  
  77. }
  78.  
  79. /* function returning the Cube of a number */
  80.  
  81. int Cube(int value)
  82.  
  83. {
  84. return value*value*value;
  85.  
  86. }
Success #stdin #stdout 0s 9432KB
stdin
25
1
25
2
-25
stdout
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: Square of 25 is 625
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: Cube of 25 is 15625
Enter a positive Integer
: