C++ Program to Reverse String

Write C++ Program to Reverse String

// CPP Program to Reverse String

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	int i, temp;
	char S[] = "CodeCrucks";

	cout << "String :--> : " << S ;
//	cout << strrev(S);   // Using inbuilt function
	int n = strlen(S);

	for(i = 0;i < n/2 ;i++)    //Doing Manually
	{
		temp = S[i];
		S[i] = S[n - i - 1];
		S[n - i - 1] = temp;
	}

	cout << "\nReverse String :--> : " << S;

	return 0;
}

Output:

String :--> : CodeCrucks
Reverse String :--> : skcurCedoC

≪ Previous | Next ≫