For this project, you will test numbers to see if they are P196 numbers. Take any number, reverse the order of the digits in that number and add these two numbers together. Repeat this process until the resulting number is a palindrome, or until the number exceeds the bounds for the data type. If a palindrome is the result of this process, then the number is a P196 number. Otherwise, it is not. For example, consider the number 1563.

1563 + 3651 = 5214
5214 + 4125 = 9339
9339 is a palindrome, so 1563 is a P196 number

For this assignment, we will use the bottom-up method. Implement the following functions in the order given. Do num_digits first. In the other functions, if you need to know the number of digits in a number you must use this function. This applies as you continue. You WILL be marked down if you do not follow these specifications.

1.unsigned num_digits ( unsigned long l);
2.int nth_digit(unsigned long l, unsigned n);
3.unsigned long rev_digits(unsigned long l);
4.bool is_palindrome(unsigned long l);
5.bool P196(unsigned long l);

You must not use any built-in C/C++ functions in your implementations. After you have written each function, write a test main, test your code and ensure that it works correctly. Be sure to test the boundary conditions. For example, for the first functions, these values would include (but might not be limited to) 0, 1, 9, 10, 11, 99, 100, 101, , ULONG_MAX-1, ULONG_MAXi .

You must not convert your number to characters!

unsigned num_digits ( unsigned long l);

This function will take any unsigned long and return the number of digits in this number. For example, if l = 105, your function must return 3. If you are bored with this assignment, make your function recursive.

int nth_digit(unsigned long l, unsigned n);

This function will take any unsigned long l in the range 0-ULONG_MAX and an unsigned int n. It will return the nth digit of l. If n is too large, it will return 1. The digit in the ones place is the 0th digit. For example, if l==12035, and n==0 your function must return 5. If n==1, 3; n==4, 1. For this example, if n is greater than 4 your function must return 1. You must not use any built-in functions in your implementation. NOTE: this is just an example of all of the numbers in this range. If you are bored, write this function recursively.

unsigned long rev_digits(unsigned long l);

This function will take any unsigned long l in the range (0-ULONG_MAX). It will return an unsigned long that has the digits reversed. For example, if l==12035, the function will return 53021. If l==12030, the function will return 3021.

In your implementation of this function, you may find that you need to know the number of digits in l. If you do, you must use your num_digits function. Likewise, if you decide that you need to access the individual digits of l, you must use your nth_digit function. You must not use any built-in functions in your implementation.

You must not convert your number to characters!

Note: Some numbers may be out-of-range when reversed; you do not need to worry about these.

bool is_palindrome(unsigned long l);

This function will take any unsigned long l in the range (0-ULONG_MAX). It will return true is the number is a palindrome, false otherwise. For example, if l==12035, the function will return false. If l==1203021, the function will return true. Note that any single digit number is a palindrome.

In your implementation of this function, you may find that you need to know the number of digits in l. If you do, you must use your num_digits function. Likewise, if you decide that you need to access the individual digits of l, you must use your nth_digit function. You must use your rev_digits function to determine if the number is a palindrome.

bool P196(unsigned long l);

This function will take any unsigned long in the range 0-ULONG_MAX. It will return true if the number becomes a palindrome using the reverse and add process that we have discussed in class, false otherwise. For example, if l==10, the function would produce the following sequence: 10, 11 and will return true. Your function will return false if the results of an addition will be larger than an unsigned long that can be reversed.

When you are sure that they all work, test the numbers in the range 10 MAX_TEST, and print out the results. Try different values for MAX_TEST.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.