How to reverse a string using a recursive function, with swapping


#include<stdio.h>
#include<conio.h>
char a1[50];  //GLOABAL VAR.
void reverse(int);
void main()
{
int count=0;
printf("enter the string :");
scanf("%s",a1);
for(int i=0;a1[i]!='\0';i++)
count++;
reverse(count);
getch();
}

void reverse(int count1)
{
char temp;
static int i=0;
  if(i<=count1/2)
    {
   temp=a1[i];
    a1[i]=a1[count1-1];
    a1[count1-1]=temp;
    i++;
   reverse(--count1);
    }
   else
    printf("\nthe reversed string is :%s",a1);
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples