C //练习 4-13 编写一个递归版本的reverse(s)函数,以将字符串s倒置。

C程序设计语言 (第二版) 练习 4-13

练习 4-13 编写一个递归版本的reverse(s)函数,以将字符串s倒置。

注意:代码在win32控制台运行,在不同的IDE环境下,有部分可能需要变更。
IDE工具:Visual Studio 2010

 

代码块:
#include 
#include 

static int i = 0;
static int j = 0;

void reverse(char s[]){
	char c = '\0';

	if(s[i] != '\0'){
		c = s[i++];
		reverse(s);
	}
	if(j < i && c != '\0'){
		s[j++] = c;
	}
}

int main(){
	char s[] = "hello world!";
	reverse(s);
	printf("%s\n", s);

	system("pause");
	return 0;
}

你可能感兴趣的:(#,C程序设计语言(第二版)练习题,C/C++,c语言,算法)