C语言反转字符串输出,要求使用递归算法实现。不用递归很简单,可是用递归怎么实现呢?
#include <stdio.h>
void foo(char * s)
{
if (*s != '\0')
foo(s + 1);
printf("%c", (char)*s);
}
int main()
{
char s[] = "hello world";
foo(s);
}
#include<iostream>
using namespace std;
void invert(char *p)
{
if(*p)
{
invert(p+1);
cout<<*p;
}
}
void main()
{
char str[]="i love visual c++";
invert(str);
}