/* These are the 6 steps for solving the problem of finding the sum of 2 integer numbers using function */ Step 1: Define the problem requirements From the problem description, the requirement is very clear. The program accepts as its input data two integer numbers like 50 and 30. The program will output the sum of the two integer numbers. Step 2: Identifying problem components: This shows all input data, output data and relationships between input and output Data expressed in formulas. Input data: Number1, Number2 (integer); Output data: Sum (integer) Other data: Relationships: Sum = Number1 + Number2; Step 3: Break problem solution into small problem modules. The structure chart has only one function, called FindSum (with reference number 1000), which is directly called by Main (Control Module with reference 0000). Step 4:Design the algorithm to solve the problem (I will follow the general algorithmic structure provided as slide 52 or on page 46 as Fig. 3.1 of book). Note that since there is one other function 1000 in addition to the main function, I will have to provide both the function prototype and function definition of this function and ensure that the function is properly called by main. /* Function Prototype is given next */ int FindSum(int, int); MainAlgorithm { input data: Number1, Number2 (integer); output data: Sum (integer), Other data: /* Sequence of steps begins here */ Print("Welcome to the Adder Program"); Print("Please type two integer numbers like 5 and 10"); Read(Number1, Number2); /* now compute the output Sum by calling function FindSum*/ Sum = FindSum(Number1, Number2); /* Now print the desired output for the user */ Print(" The sum of Number1 and Number2 = ", Sum); } /* Now, the define the function FindSum */ int FindSum(int first, int second) { int sum; /* This is a local variable of FindSum */ sum = first + second; return(sum); } Step 5: Implementation of the algorithm(this is designed using the general structure of a C program provided as slide 53 or on Page 47 as Fig 3.2 of book) Again, like in the algorithm, there is one other function 1000 in addition to the main function, I will have to provide both the function prototype and function definition of this function and ensure that the function is properly called by main. #include /* Function Prototype is given next */ int FindSum(int, int); int main(void) { /* Program to find the sum of two given integers */ /* We first declare the input and output data */ int Number1, Number2; int Sum; /* Sequence of steps begins here */ printf("Welcome to the Adder Program \n"); printf("Please type two integer numbers like 5 and 10 \n"); scanf("%d %d", &Number1, &Number2); Sum = FindSum(Number1,Number2); printf(" The sum of %d and %d = %d \n", Number1, Number2, Sum); return 0; } /* Now, the define the function FindSum */ int FindSum(int first, int second) { int sum; /* This is a local variable of FindSum */ sum = first + second; return(sum); } Step 6: Testing and Verifying the solution for correctness. This traces through the algorithm and program to ensure that with a set of given input data they produce expected results. Assume we test the problem by inputing the values 5 and 10 for Number1 and Number2. At the beginning of the program all variables declared are reserved with the following initial values as indicated in the program: The CPU will execute the sequence of instructions as follows: a)First executable instruction scanf("%d %d", &Number1, &Number2) has the effect of reading 5 into Number1 and 10 into Number2; b)The next program instruction FindSum(Number1, Number2) has the effect of passing the value 5 from main's Number1 to FindSum's formal parameter first, while the value 10 of main's Number2 is passed to the function FindSum's formal parameter second. These are call-by-value parameters. c) Now, control has jumped to the definition of FindSum, where the instructions of this function are completly executed before execution control returns to the main program at the point of the call. Thus, in FindSum, local variable sum = first + second = 5 + 10 = 15. The last instruction of FindSum returns sum = 15 to main. d) Now, in main, the instruction Sum = FindSum(Number, Number2) after execution of FindSum has Sum = 15. e)the last instruction displays the output result to the user as: The sum of 5 and 10 = 15. END