05 Functions
05 Functions
(UCS540)
February 6, 2023
SDLC
PROBLEM
Get distance travelled in miles. Convert it in to kilometers.
Analysis
Input:distance in miles. Only one output : distance in
kilometers.
Type of both variables: double.
DATA REQUIREMENTS
Problem Constant: KMS PER MILE 1.609
Problem Input: miles /* distance in miles */
Problem Outputs : kms /* distance in kilometers */
Relevant Formulas
distance in kms = distance in miles × 1.609
The subprogram prototypes precede the main function (after any in-
clude or define directives) and the subprogram definitions follow the
main function.
The relative order of the function definitions does not affect their order
of execution
Example
The function call scale(3.7, 2) returns 370.0 (3.7 × 102 )
The function call scale(3.7, −2) returns 0.037 (3.7 × 10−2 ) Exe-
cutable stmt in function scale : scale factor = pow (10, n);