C Programming Description

This software will allow you to enter the number. It reduces the number by dividing it by two. It will continue to request input from the user until the user inputs the number 0.


I will use the same programming technique of repetition, selection, and sequential statements.


I'll define one integer variable and one double variable. The integer variable will store the input number, while the double variable will store the shrunk value.


The Shrink function will take an integer and divide it by 2 to return its shrink value. A fractional value can be obtained by dividing an integer by two.


So the data type of the return type would be double.


Result = value/ 2;


For instance, if 9 were passed to the function, it will return Result as


Result = 9/2 = 4.5


A repetition loop will be used to loop through iterations until a negative number is entered that is:


While(intValue > 0) (



End While


Pseudocode


// This program will shrink the value of a number by dividing it by 2


// Start Main program


Main


// Declare variables


Declare intValue as Integer


Declare Result as Double


// Set intValue to positive value to start loop


Set intVal = 1;


// Loop While input is a positive number


While intValue > 0


Print "Enter a positive Integer:”


Input intValue


if intValue > 0


Result = Shrink(intValue);


Print "Shrinked value of "+ intValue +"is " + Result


}


END While


// End of Main program


End Program


// Shrink Function


Function Shrink(value) as Integer


return value / 2


End Function


C Code


The C code that will compile and execute in online compilers is as follows;


// C code


// This program will shrink the value of a number by dividing it by 2


// Developer:


// Date:


#include


double Shrink(int);


int main()


{


/* variable definition: */


int intValue;


double Result;


intValue = 1;


// While a positive number


while (intValue > 0)


{


printf("Enter a positive Integer\n: ");


scanf("%d", &intValue);


if (intValue > 0)


{


Result = Shrink(intValue);


printf("Shrinked value of %d is %lf\n", intValue, Result);


}


}


return 0;


}


/* function shrinks the number by dividing it by 2 */


double Shrink(int value)


{


return (double)value / 2;


}


Test Plan


To verify this program is working correctly, following input variables were utilized for testing purposes:


Test Case


Input


Expected Output


1


IntValue = 8


Shrinked value of 8 is 4.0


2


IntValue = 17


Shrinked value of 17 is 8.5


3


IntValue = 20


Shrinked value of 20 is 10


4


IntValue = 0


Shrinked value of 0 is 0


Setting up the code and the input parameters at ideone.com:


Note the input values for this run were:


8


17


20


0


Results from running the programming at ideone.com:


Answer 3


If the code ”if intValue>o” is removed from the design, then the program will process the values that are equals to zero or less than zero. It will calculate the Shrink value for the negative number, and there will be no check for a positive number. However, it will execute the code only for one time after that it will then execute the loop in iterations.


Answer 4


In modifying the original code, I have added an additional function Expand that will expand the number by multiplying it by 2. The function is unique since it will expand the number by multiplying it by 2 instead of shrinking the number by dividing it by 2.


C Code


// C code


// This program will shrink the value of a number by dividing it by 2


// and expands it by multiplying it by 2


// Developer:


// Date:


#include


double Shrink(int);


int Expand(int);


int main()


{


/* variable definition: */


int intValue, ResultExpand;


double Result;


intValue = 1;


// While a positive number


while (intValue > 0)


{


printf("Enter a positive Integer\n: ");


scanf("%d", &intValue);


{


Result = Shrink(intValue);


printf("Shrinked value of %d is %lf\n", intValue, Result);


ResultExpand = Expand(intValue);


printf("Expanded value of %d is %d\n", intValue, ResultExpand);


}


}


return 0;


}


/* function shrinks the number by dividing it by 2 */


double Shrink(int value)


{


return (double)value / 2;


}


/* function expands the number by multiplying` it by 2 */


int Expand(int value)


{


return 2 * value;


}


Test Plan for new method


To verify the new function is working correctly, following input variables can be used for testing purposes;


Test Case


Input


Expected Output


1


IntValue = 6


Expanded value of 6 is 12


2


IntValue = 25


Expanded value of 25 is 50


3


IntValue = 14


Expanded value of 14 is 28


4


IntValue=0


Expanded Value of 0 is 0


Setting up the code and the input parameters at ideone.com:


Note the input values for this run were:


6


25


14


0


Results of running program on ideone.com

Deadline is approaching?

Wait no more. Let us write you an essay from scratch

Receive Paper In 3 Hours
Calculate the Price
275 words
First order 15%
Total Price:
$38.07 $38.07
Calculating ellipsis
Hire an expert
This discount is valid only for orders of new customer and with the total more than 25$
This sample could have been used by your fellow student... Get your own unique essay on any topic and submit it by the deadline.

Find Out the Cost of Your Paper

Get Price