Here, we have a basic program example to print the characters of a string in reverse order using different languages. This program is created in c language, c++, Java, and Python.
Code to print string characters in reverse order in C language
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | #include <stdio.h> #include <string.h> #include <stdlib.h> void main() { char str[100]; int len,i; printf ( "Input the string : " ); fgets (str, sizeof str, stdin); len= strlen (str); printf ( "The characters of the string in reverse are : \n" ); for (i=len;i>=0;i--) { printf ( "%c " , str[i]); } printf ( "\n" ); } |
Code to print string characters in reverse order in C++ language
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main() { char str[200], ch; int i, j, len; cout<< "Enter the String: " ; cin>>str; len = strlen (str); cout<< "The characters of the string in reverse are : " <<endl; for (i=len;i>=0;i--) { cout<< " " <<str[i]; } return 0; } |
Code to print string characters in reverse order in Python language
1 2 3 4 5 | str = input ( "Enter the String : " ) count = len ( str ) print ( "The characters of the string in reverse order are: " ) for i in range (count - 1 , - 1 , - 1 ): print ( " " , str [i]) |