fork download
  1. #include <stdio.h>
  2. // Function prototypes
  3. int Square(int value);
  4. int Cube(int value);
  5. int main ()
  6. {
  7. /* variable definition: */
  8. int intValue, menuSelect,Results;
  9. intValue = 1;
  10. // While a positive number
  11. while (intValue > 0)
  12. {
  13. printf ("Enter a positive Integer\n: ");
  14. scanf("%d", &intValue);
  15. if (intValue > 0)
  16. {
  17. printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: ");
  18. scanf("%d", &menuSelect);
  19. if (menuSelect == 1)
  20. {
  21. // Call the Square Function
  22. Results = Square(intValue);
  23. printf("Square of %d is %d\n",intValue,Results);
  24. }
  25. else if (menuSelect == 2)
  26. {
  27. // Call the Cube function
  28. Results = Cube(intValue);
  29. printf("Cube of %d is %d\n",intValue,Results);
  30. }
  31. else
  32. printf("Invalid menu item, only 1 or 2 is accepted\n");
  33. }
  34. }
  35. return 0;
  36. }
  37. /* function returning the Square of a number */
  38. int Square(int value)
  39. {
  40. return value/2;
  41. }
  42. /* function returning the Cube of a number */
  43. int Cube(int value)
  44. {
  45. return value*value*value;
  46. }
Success #stdin #stdout 0s 9432KB
stdin
4
1
-1
stdout
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: Square of 4 is 2
Enter a positive Integer
: