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