eCstring() Test #1keyboard_arrow_up 0 / 1   Your output Array before performing reverse operation: r e v e r s e Array after performing reverse operation: r r e v e s e Test feedback reverseCstring("reverse") should change the c-string to "esrever" not rrevese 2:reverseCstring() Test #2keyboard_arrow_up 0 / 1   Your output Array before performing reverse operation: C a n y o u r e v e r s e t h i s ? Array after performing reverse operation: C y n a o u r e v e r s e t h i s ? Test feedback reverseCstring("Can you reverse

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
1:reverseCstring() Test #1keyboard_arrow_up
0 / 1
 
Your output
Array before performing reverse operation: r e v e r s e Array after performing reverse operation: r r e v e s e
Test feedback
reverseCstring("reverse") should change the c-string to "esrever" not rrevese
2:reverseCstring() Test #2keyboard_arrow_up
0 / 1
 
Your output
Array before performing reverse operation: C a n y o u r e v e r s e t h i s ? Array after performing reverse operation: C y n a o u r e v e r s e t h i s ?
Test feedback
reverseCstring("Can you reverse this?") should change the c-string to "?siht esrever uoy naC" not Cy naou reverse this?
#include <stdio.h>

void reverseWithinBounds(char a[], int l, int r)
{
    if (l < r)
    // Checking for the condition when l is less than r
    {
        char temp;
        temp = a[l];
        a[l] = a[r];
        a[r] = temp;
        // swapping the characters present at the position l and r

        l++;
        r--;
        // Updating l and r

        reverseWithinBounds(a, l, r);
        // making a recursive call
    }
}

void reverseCstring(char a[])
{
    int n = 0;
    while (a[n] != '\0')
        n++;
        // Finding the size of the array

    printf("Array before performing reverse operation: ");
    for (int i = 0; i < n; i++)
    {
        printf("%c ", a[i]);
    }
    // printing the array before performing reverse operation

    printf("\n");

    reverseWithinBounds(a, 1, 4);
    // making a function call passing array and bounds to the function

    printf("Array after performing reverse operation: ");
    for (int i = 0; i < n; i++)
    {
        printf("%c ", a[i]);
    }
    // printing the array after performing reverse operation
}
int main()
{
    char a[6] = {'A', 'B', 'C', 'D', 'E', '\0'};
    // Declaring a character array

    reverseCstring(a);
    // making a function call passing array to the function
    return 0;
}
 
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT