데이터 구조P17

역귀 편
# include 
/**
*	           
*	2016 6 18 21:11:00
*/

void f();
void g();
void k();	//      ,main  f g k     ,  f g k           !

void f()
{
	printf("FFFFFF
"); g(); printf("111111
"); } void g() { printf("GGGGGG
"); k(); printf("222222
"); } void k() { printf("KKKKKK
"); } int main(void) { f(); // FGK21 return 0; }

p17_2:
# include 
/**
*	        ,  
*	2016 6 18 21:22:55
*/

void f(int n)
{
	if(n == 1)
		printf("  
"); else { printf("gg
"); f(n-1); // , } } int main(void) { f(6); // :gggggggg return 0; }

p17_3:
# include 
/**
*	        
*	2016 6 19 12:23:21
*/

int factorial(int);

int main(void)
{
	int n = 4;
	printf("%d
", factorial(n)); return 0; } int factorial(int n) { if(1 == n) //== : !! return 1; else return (n*factorial(n-1)); }

p17_4:
# include 
/**
*	        
*	2016 6 19 12:23:21
*/

int factorial(int);

int main(void)
{
	int n = 4;
	printf("%d
", factorial(n)); return 0; } int factorial(int n) { int fac = 1; for(n; n>=1; n--) { fac = n*fac; } return fac; }

p17_5:
# include 
/**
*	 1+2+3+...100     
*	2016 6 19 12:53:17
*/

int sum(int);

int main(void)
{
	int n = 100;
	printf("%d
", sum(n)); return 0; } int sum(int n) { if(1 == n) return 1; else return (n+sum(n-1)); }

p17_6:
# include 
/**
*	    、              ;           
*	2016 6 19 12:53:17
*/

void f(int);
void g(int);

void f(int n)
{
	g(n);
}

void g(int m)
{
	f(m);		//    
}
int main(void)
{
	f(5);
	return 0;
}

P17_7:
# include 
/**
*	      : A n     B   C
*	   :
*	if(n>1)
*	{
*	1.   A (n-1)   C   B;(       ,     ABC  ,       !)
*	2.  A  n        C;
*	3.   B (n-1)     A   C( 1    ,     ABC  )
*	}	s	
*	2016 6 19 14:41:17
*/

void hannuota(int, char, char, char);

int main(void)
{
	char ch1 = 'A';
	char ch2 = 'B';
	char ch3 = 'C';
	int n;

	printf("           : ");
	scanf("%d", &n);

	hannuota(n, ch1, 'B', 'C');	//   : A  n    B   C(ps:ch1 'A'  )


	return 0;
}
/**
void hannuota(int n, char A, char B, char C)
{
	   1   
		   A   A  C
	  
		  A    n-1     C  B;
		   A   n    A  C;
		 B  n-1     A  C
}
*/

void hannuota(int n, char A, char B, char C)	//A  B  C
{
	if(1 == n)
		printf("    %d      %c    %c  
", n, A,C ); else { hannuota(n-1, A, C, B); printf(" %d %c %c
", n, A,C ); hannuota(n-1, B, A, C); } }

좋은 웹페이지 즐겨찾기