Question: The idea behind this program is to give you practice writing functions. You will be writing 2 functions and calling one from another and the

The idea behind this program is to give you practice writing functions. You will be writing 2 functions and calling one from another and the other one from main. By the end of this problem, you should be able to understand how passing parameters and returning values work. The best thing about functions is that they allow us to write individual functions assuming the other functions work as expected, even if they havent been defined yet.

First, write the reverse function. This function takes one integer argument and returns an integer as well.

We have separated the digits of the number and printed them off individually in a class example. We can modify that function to calculate the reverse instead.

The idea here, is we declare a new number before the loop and initialize it to 0. Then, in the loop, once we have separated the current digit into the remainder, multiply the new number by 10, add the current remainder and then put it back into the new number.

Once the loop is done, return the new number.

Next, write a function called difference that accepts an integer as a parameter and returns an integer as well.

Call the reverse function to find the reverse of the number (this number will be passed into the function as an argument). Then subtract the reverse from the original number.

Get the absolute value of the difference. You can use the method used in class or call the predefined function abs in the cmath library.

Return the absolute value. 1

In main, declare a sum variable that will accumulate the sum.

In a loop, accept numbers from the user. Stop if the enter 0. Otherwise, call the difference function to get the special difference of the number and add it to the sum.

Once youre out of the loop, print the sum of the special differences.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!