C Program to Reverse a String

In this tutorial you will learn about the C Program to Reverse a String and its application with practical example.

C Program to Reverse a String

In this tutorial, we will learn to create a C program that will Reverse a String in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Usage of Conditional statements in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C Programming.

What is reversing a string?

A string is a collection of words, numbers, and symbols. The String can be any sentence of English Language. Reversing a string means writing the sentence or a string in reverse order from last to first.

Algorithm:-

Program Description for Reversing the String:-

In this program, We will first take the input string from the user in string format. Then we will find the length of that string using strlen(); after that reversing that string using the for-loop. Storing the reversed sentence in a variable. Printing the reversed string from the program.

With the help of the below, code we will Reverse the String.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • str = string type variable that will hold the value of the input sentence.
  • i = it will hold the integer value.
  • len  = it will hold the integer value.
  • flag = it will hold the temporary integer value.

Input string from the user for the program.

Reverse The string.

Printing the reversed string.

In this tutorial we have learn about the C Program to Reverse a String and its application with practical example. I hope you will like this tutorial.