C Program to Reverse String using For Loop

C Program to Reverse String using For Loop

Write C Program to Reverse String using For Loop

// C Program to Reverse String

#include <stdio.h>
#include <string.h>

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

	printf("String :--> : %s",S);
//	printf("%s",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;
	}

	printf("\nReverse String :--> : %s",S);

	return 0;
}

Output:

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