30 likes | 169 Views
Recursion 遞歸. 5 4 3 2 1. A5 A4 A3 A2 A1. void count_down ( int count) { for( i =count; i >1; i --) printf (" %dt", count); }. printf (" A %d <br>", count ); if(count>1) count_down (count-1); printf (" B %d <br>", count );. A 5 count_down (4); B 5. A 4 count_down (3);
E N D
Recursion 遞歸 5 4 3 2 1 A5 A4 A3 A2 A1 void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n", count); A5 count_down(4); B5 A4 count_down(3); B4 B1 B2 B3 B4 B5 A3 count_down(2); B3 A2 count_down(1); B2 A1 B1 main (){ count_down(5); }
countDown(4) A4 A3 A2 A1 printf("A%i", count); A4 countDown(3) printf("B%i", count); B4 B1 B2 B3 B4 printf("A%i", count); A3 countDown(2) printf("B%i", count); B3 printf("A%i", count); A2 countDown(1) printf("B%i", count); B2 printf("A%i", count); A1 countDown(?) B1 printf("B%i", count);
1 A4 Recursion 遞歸 2 3 A3 4 A2 void count_down (int count) { } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n", count); A1 B1 B2 main (){ count_down(4); } B3 B4