hello guys im practicing my recursion skills and i found this problem somewhere
that wants to reverse a string recursively so if we have for example "abc" it will make it "cba"
this is my try
Code:
#include <stdio.h>
char reverse(char a[], int n,int k){
char t;
if (n==(k-1) || n==k){
return;
}
t = a[n];
a[n] = a[k];
a[k] = t;
return reverse(a,n-1,k+1);
}
int main(void){
char x[] = "HELLO WORLD";
reverse(x,strlen(x)-1,0);
printf("%s\n",x);
getchar();
return 0;
}
tell me what you think about it, also if you can tell me how to make it better maybe use less variables or stuff like that
Different code versions of this problem would be highly appreciated too
thanks in advance