;

C Program to Reverse String without using strrev() and using strlen() and using temp variable and print directly


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to reverse a string without using strrev() and using strlen() and using temp variable and print directly.

Here is the code of the program to reverse a string without using strrev() and using strlen() and using temp variable and print directly.

Code - C Program to Reverse String without using strrev() and using strlen() and using temp variable and print directly
/* C Program to Reverse String without using strrev() and using strlen() and 
using temp variable and print directly*/
		
#include<stdio.h>
#include<string.h>
void main()
{
	char str[100], temp;
	int i=0, len;
	printf("Enter a String: ");
	gets(str);
	len=strlen(str)-1;
	while(i<len)
	{
		temp=str[i];
		str[i]=str[len];
		str[len]=temp;
		i++;
		len--;
	}
	printf("Reverse String is = %s",str);
}
Output

Enter a String: Tutorialsrack
Reverse String is = kcarslairotuT
--------------------------------
Process exited after 6.703 seconds with return value 33
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags