1.

Write down a string reversal algorithm. If the given string is "kitiR," for example, the output should be "Ritik".

Answer»

An algorithm for string reversal is as follows:

  • Step 1: Start.
  • Step 2: We take two variables l and r.
  • Step 3: We set the values of l as 0 and r as (LENGTH of the string  - 1).
  • Step 4: We INTERCHANGE the values of the characters at positions l and r in the string.
  • Step 5: We increment the value of l by one.
  • Step 6: We DECREMENT the value of r by one.
  • Step 7: If the value of r is greater than the value of l, we go to step 4
  • Step 8: STOP.


Discussion

No Comment Found