- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
To reverse a string in C++ programming, then ask to the user to enter a string, now make a variable say temp of char type and start swapping. Place first character of the string in temp and last character of the string in the first, then place temp in the last and continue, to swap string as shown in the following program.
Source Code: Print Reverse of a String
/* C++ Program - Reverse String */ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { clrscr(); char str[100], temp; int i=0, j; cout<<"Enter the String : "; gets(str); j=strlen(str)-1; while(i<j) { temp=str[i]; str[i]=str[j]; str[j]=temp; i++; j--; } cout<<"Reverse of the String = "<<str; getch(); }Output
Enter the String : Hello Reverse of the String = olleH