By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,483 Members | 3,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,483 IT Pros & Developers. It's quick & easy.

Can someone please explain to me what is my teacher asking me?

P: 64
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be great. I know its sorta long, but maybe you only have to few the first few paragraphs.



Problem:
Write a program in C that generates number palindromes using the algorithm below (see 3. on the next page) and allows the user to try this algorithm several times. Even though you will be generating number palindromes, you will be using C strings due to overflow problems. Therefore, you will need to declare 2 strings in main, one for input (declare with size of 7) and the other for output (declare with size of 81) (be sure to #define this size).

Main will have the loop that will call several different functions until the user indicates to not repeat (see below). The functions called from main are:
**function to get a positive integer from the user (see details in 1. below)
function that checks if the input string is an positive integer (all characters are digits-- see details in 2. below), and returns in a return statement 1 for true (if it is), 0 for false (if not).
IF function 2. returns true, then call
 the function to create a palindrome using the input integer (see details in 3. below). This function requires you have a pointer parameter.
 the function to print the input string, palindrome (output) string, and how many iterations of the algorithm it took (int) with labels (see test runs)
function to ask the user and read if he/she wants to try another and repeat to ** if this function returns a non-zero int (see details in 4. below)
More about the functions:
1. In the function that reads a positive integer, prompt the user for and read a positive integer up to 5 digits long INTO A LOCAL TEMPORARY STRING of size 21 using fgets. After reading into the string, remove leading and trailing white spaces (spaces, tabs or newlines) by calling another function (that you write, see details in 5. below) to remove these. Then copy from the temporary string into the string parameter (that will actually be the pointer to the beginning char in the input string declared in main), AT MOST 5 characters (+ null char) using the appropriate <string.h> function.
2. In the function that checks if a string is a positive integer, be sure to check each char (up to null char) to see if it's a "digit character". Return in a return statement, 1 if it is, 0 if not.
3. In the function that generates a "number palindrome", you will assign to the string parameter (that points to the output string in main) the resulting string AND assign to an int in main using a pointer parameter how many iterations were done of the following algorithm (be sure to put a copy of the input string to the output string parameter, since the result could become larger than the input):
Find the reverse of the string (BUT DON'T CHANGE THE STRING YOU'RE FINDING THE REVERSE OF)
**If the reverse does NOT have the same characters as the string, the do the following
o Call a function (that you write) to ADD the string and it's reverse and put the result in the string (so it changes). REMEMBER THAT STRINGS HAVE THE character (ASCII) codes, so you have to "adjust"
o Find the reverse of the string (again, don't change the string)
o Repeat to ** until the string and its reverse are the same
In the above loop, be sure to keep count of how many times you executed the body of the loop. This count will be for the int pointer parameter mentioned above.
4. In the function that returns whether or not the user wants to continue, after prompting the user, read the user's answer up to the end of the line into a local string. Call the function to remove white spaces (using the same function #5), on the local string. If the beginning char is upper OR lower case 'N', return 0-- otherwise return 1. BE SURE TO USE <ctype.h> functions in this function! (continued on the next page ===>)
5. In the function that removes leading and trailing white spaces in a string parameter, you will be changing the string, which will be the ONLY parameter in this function. Also use a <ctype.h> function in this function.



Expand|Select|Wrap|Line Numbers
  1. Use the input on the G: drive (Lab2InputForTurningIn.doc) for turning in.  Be sure to try with test runs input values as well.
  2.  
  3. Lab 2 Input for Turning In:
  4. Enter a positive integer (up to 5 digits):    34
  5. Try another? (n for no):    yes
  6. Enter a positive integer (up to 5 digits):    567
  7. Try another? (n for no):    Yes
  8. Enter a positive integer (up to 5 digits):    898
  9. Try another? (n for no):    ok
  10. Enter a positive integer (up to 5 digits):    123454321
  11. Try another? (n for no):    sure
  12. Enter a positive integer (up to 5 digits):    what?
  13. Try another? (n for no):    Y
  14. Enter a positive integer (up to 5 digits):    89
  15. Try another? (n for no):    please
  16. Enter a positive integer (up to 5 digits):    -45654 (note the negative sign)
  17. Try another? (n for no):    y
  18. Enter a positive integer (up to 5 digits):    98798
  19. Try another? (n for no):    YEAH
  20. Enter a positive integer (up to 5 digits):    8
  21. Try another? (n for no):    NO
  22.  
  23.  
  24.  
May 7 '07 #1
Share this Question
Share on Google+
1 Reply


gpraghuram
Expert 100+
P: 1,275
HI,
Palindrom is the one which is same word read from both the directions

9889 is a number plaindrome
123321 is another example...
If u are asking help with urhome work the the forum guidelines dosent allow that

Thanks
Raghuram
May 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.