C++ Online Compiler
Example: Reverse a String in C++ using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Reverse a String in C++ using For loop #include <iostream> using namespace std; int main() { char x[100], y[100]; int b, e, c = 0; // b - To store the begin character // e - To store the end character // c - To store the string count cout << "Enter a string to make reverse::\n"; cin >> x; // calculation of the string length while (x[c] != '\0') { c++; } e = c - 1; for (b = 0; b < c; b++) { y[b] = x[e]; e--; } y[b] = '\0'; cout << "The reverse of the string is : " << y << "\n"; return 0; }
example
Output
Clear
ADVERTISEMENTS