Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write this program in the language C. The program should compile and meet

ID: 3554158 • Letter: P

Question

Please write this program in the language C. The program should compile and meet requirements below in order to be chosen as Best Answer.



Program - Recursion As we discussed in class, recursion is a very useful programming technique in which a function makes a call to itself. Such a call is described as a "recursive function call." Recursion can be applied successfully to any problem in which the overall solution can be calculated from smaller portions of the original problem. Although it incurs extra overhead in terms of time and memory, recursion's main advantage is that it can often vastly simplify the code. The following examples will illustrate this. For this assignment, let's write recursive functions that solve three different problems: Determining if a string is a palindrome or not. Printing the characters of a string backwards instead of forwards. Calculating the Greatest Common Divisor (GCD) of two integers. All of these problems should be solved by a separate recursive functions. You can determine what the prototypes should be. In all cases, analyze the problem space for two characteristics: what the base case should be, and (b) how a larger problem can be solved by making recursive calls to smaller, but similar problems. That will tell you how to set up the selection logic statement that is necessary in a recursive function. In general, your program should do the following: Ask the user to input a character string. Determine whether it is a palindrome or not (by using the recursive function), report the result to the user, and print the string in reverse (also by using the recursive function).

Explanation / Answer

1)

For Palindrome :


#include <stdio.h>

#include <string.h>


int is_palindrome(int start, int end, char *str)

{

if (str[start] != str[end])

return 0;

else if (start == end)

return 1;

else

return is_palindrome(++start, --end, str);


return 0;


}

int main()

{

char str[20];

printf("Enter the String. ");

fgets( str, sizeof( str ), stdin );

int length=strlen(str);

int start=0,end=length-1;

int result;

if(is_palindrome(start,end,str))

printf("It's a palindrome! ");

else

printf("It's not a palindrome! ");

return 0;

}



2) For Reverse Printing

Answer was getting more than 65000 character limit so here is link to this answer : http://ideone.com/zeqor5