Write a program that performs a reverse recursion with following functions.
void swop (char[ ],int,int);
void reverse (char[ ]);
void rev(char[ ],int, int);
User should enter a string and all character should be reversed. Note! The
rev function should be used as the recursive function, accepting the string, plus
the first and last position of string. The reverse() passes the first and the last
position of the string to the rev() which performs the recursive operation. The
swop() accepts the string with the first and the last position of the string.
e.g. The string "Testing" is reversed to "gnitseT"
This is what i did, but its not working... Pls help
void swop (char[ ],int,int);
void reverse (char[ ]);
void rev(char[ ],int, int);
User should enter a string and all character should be reversed. Note! The
rev function should be used as the recursive function, accepting the string, plus
the first and last position of string. The reverse() passes the first and the last
position of the string to the rev() which performs the recursive operation. The
swop() accepts the string with the first and the last position of the string.
e.g. The string "Testing" is reversed to "gnitseT"
This is what i did, but its not working... Pls help
Code:
#include <stdio.h>
#include<string.h>//header for string function like strlen
void swop (char[ ],int,int);
void reverse (char[ ]);
void rev(char[ ],int, int);
void main()
{
char str[100];//declare a string with maximum length ofa 100
printf("\nPlease enter the string: ");//prompts user for a string
rev(str ,0, strlen(str));
reverse(str);
}
void swop (char str1[ ],int first1,int last1)
{
rev(str1,first1,last1);
for(int x=first1;x < last1;x++)
{
if (str1[x]==first1)
{
swop(str1,last1,first1);
printf("%c",str1[first1]);
}
else
{
swop(str1,last1-1,first1+1);
}
void reverse (char str[100])
{
if(str != '\0')
{
reverse(str+1);
printf("%c",str);
}
}
void rev(char str2[] ,int first, int last)
{
gets(str2);
first=0;
last=strlen(str2);
}
Comment