Looking for NEET / JEE Coaching? Enquire Now
You must Sign In to post a response.
  • Category: Programming

    Program to convert the given string using recursion.


    Have a query about writing recursion based C program? Interested in scoring well in C programming language exam? Go through the responses from ISC experts here and get the answer you are looking out for.

    Following is a question that was asked in the MSBTE (Maharashtra State Board of Technical Education, Mumbai) Diploma in Electronics Engineering sample question paper of C Programming Language(22218).

    This question is asked for 04 marks and hence requires some explanation along with the program code. Please let me know the solution.

    Q) Write a C Program to convert the given string "Hello" to "olleH" using resursion.[4 Marks]
  • Answers

    1 Answers found.
  • The following code is a program to reverse a string using recursion in C programming language:

    # include
    void reverseString(char *strg)
    {
    if (*strg)
    {
    reverseString(strg+1);
    printf("%c", *strg);
    }
    }
    int main()
    {
    char a[] = "Hello";
    reverseString(a);
    return 0;
    }

    Output : olleH

    In the above code, the function reverseString is used to reverse the given string using recursion. The function takes the given string pointer as input and calls itself with the next address of the passed string since it's passed as a character array. Recursion continues till the array reaches its end ('\0') and the output is returned from the stack one by one.

    --Time is money--
    Benjamin Franklin


  • Sign In to post your comments