Ask Question
15 May, 09:49

Write a function called printBackwards () that will work with a C string. The function will print any C string backwards. You don't need to put in the prototype, but you need to write a complete function.

+3
Answers (1)
  1. 15 May, 09:59
    0
    void printBackwards (char s[])

    {

    int n=strlen (s) - 1; //finding the last index of the string ...

    for (int i=n; i>=0; i--) / /loop to print the string backwards ...

    {

    printf ("%c", s[i]); //printing the character of the string ...

    }

    }

    Output:-

    abcdefg

    gfedcba

    Explanation:

    I have used strlen function that will be used after including the string. h header file. It returns the length of the string. After finding the last index I have iterated over the c string in reverse order and printing the character of the string one by one.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function called printBackwards () that will work with a C string. The function will print any C string backwards. You don't need to ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers