Question: // C code // This program will provide options for a user to calculate the square. // or cube of a positive integer input by
// C code
// This program will provide options for a user to calculate the square.
// or cube of a positive integer input by a user.
#include
// Function prototypes
Int squares (int value);
Int cube (int value);
Int main ()
(
/* variable definition: */
Int intvalue, menuSelect,Results;
intValue = 1;
// While a positive number
While (intValue > 0)
(
printf (Enter a positive Integer : );
scanf(%d, &intValue);
If (intValue > 0)
(
printf (Enter 1 to calculate Square, 2 to calculate Cube : );
scanf(%d, &menuSelect);
If (menuSelect == 1)
{
// Call the Square Function
Results = Square (intValue);
printf(Square of %d is %d , intValue,Results );
}
else if (menuSelect == 2)
{
// Call the cube function
Results = Cube (intValue);
printf(Cube of %d is %d , intValue,Results);
}
else
Printf (Invalid menu item , only 1 or 2 is acceptable );
}
}
return 0;
}
/* function returning the Square of a number */
Int Square(int value)
{
return value*value;
}
/* function returning the Cube of a number */
Int Cube (int value)
{
Return value*value*value;
}
1. Using the Square and Cube function as models, create an application that includes a function named Shrink that would take an integer and return the integer divided by 2. (Hint: Your return variable type should be double.) support your experimentation with sceeen captures of executing the code.
2. Prepare a new test table with at least 3 distinct test cases listing input and expected output for the new code you created for the Shrink function.
3. What would happen if you removed the following code from our design ?
If intValue > 0
Support your argument with screen captures of executing the new code.
4. Modify the original code and add an additional function of your choice. The function should be unique and something you created for this assignment. Support your experimentation with screen captures of executing the new code. Prepare a test table with at least 3 distinct test cases listing input and expected output for your unique function.
.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
