4 3. A palindrome is a word such as radar that is unchanged when it is spelt backwards. The C code below tests whether a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

4 3. A palindrome is a word such as radar that is unchanged when it is spelt backwards. The C code below tests whether a

Post by answerhappygod »

4 3 A Palindrome Is A Word Such As Radar That Is Unchanged When It Is Spelt Backwards The C Code Below Tests Whether A 1
4 3 A Palindrome Is A Word Such As Radar That Is Unchanged When It Is Spelt Backwards The C Code Below Tests Whether A 1 (322.56 KiB) Viewed 38 times
4 3. A palindrome is a word such as radar that is unchanged when it is spelt backwards. The C code below tests whether a string entered from the terminal is a palindrome or not. a 1 2 #include <stdio.h> #include <string.h> 4 5 6 int palindrome (char* word_p, int j) { char forwards [jl, backwards [j]; for (int i = 0; i<j; i++) forwards = *word_p++; for (int i = 0; i<n; i++) backwards = forwards (j-i-2]; return strcmp (forwards, backwards); } 10 11 12 13 14 15 16 17 18 19 int main(void) { char word [20]; printf("Please enter a word: "); scanf("%s", word); สี สี สสี สล 21 22 23 24 25 26 27 if (palindrome (word, strlen (word) +1) ==0) printf(" " & " is a palindrome! \a \n", word); else printf("\"%s" is not a palindrome \n", word); return 0; } a) How are header comments and inline comments added to C code? [2] b) Examine the code carefully and explain briefly how it works. You should include the sort of information that ought to be present in the missing header comments. [3] c) Write down a function prototype for the palindrome() function and explain why it would be needed if the main() function were moved to the top of a file? [3] d) What does the # symbol mean on lines 1 and 2? Give another example of the use of the # symbol in a C-program, other than with the "include" statement. [2] e) Examine line 9 of the code and explain what it is doing: What sort of variable is word_p and what are the * and ++ operators doing? [3] f) Explain line 23 of the code in detail, including the \" $s and la sequences. [3] g) If the string is identified as a palindrome, we may wish to append the word to an existing file called Palindromes.txt. Write down the code required to open, append and close the file. [4]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply