#include<stdio.h>
#include<string.h>
void main()
{
int n;
scanf("%d",&n);
printf("%d ",f(n));
getch();
}
int f(int k)
{
if(k==1)
return 1;
else
return k*f(k-1); 可以解释一下这里的两个return的返回值是怎样返回的吗?
}
几乎一样好。。

抵制日货,从我做起!!!

 2006-11-22 21:07
	    2006-11-22 21:07
  
 2006-11-22 21:14
	    2006-11-22 21:14
   2006-11-22 21:14
	    2006-11-22 21:14
   2006-11-23 09:12
	    2006-11-23 09:12
  #include <assert.h>
#include <stdio.h>
#include <stdlib.h>
extern int cnt; /* count of the number of moves */
int   get_n_from_user(void);
void  move(int n, char a, char b, char c);
#include "hanoi.h"
int cnt = 0; /* count of the number of moves */
int main(void)
{
   int   n;
   
   n = get_n_from_user();
   assert(n > 0);
   /*
   // Move n disks from tower A to tower C,
   // using tower B as an intermediate tower.
   */
   move(n, 'A', 'B', 'C');      /* recursive fct */
   return 0;
}
#include "hanoi.h"
void move(int n, char a, char b, char c)
{
   if (n == 1) {
      ++cnt;
      printf("%5d: %s%d%s%c%s%c.\n", cnt,
         "Move disk ", 1, "from tower ", a, " to tower ", c);
   }
   else {
      move(n - 1, a, c, b);
      ++cnt;
      printf("%5d: %s%d%s%c%s%c.\n", cnt,
         "Move disk ", n, "from tower ", a, " to tower ", c);
      move(n - 1, b, a, c);
   }
}
#include "hanoi.h"
int get_n_from_user(void)
{
   int  n;
   
   printf("%s",
      "---\n"
      "TOWERS OF HANOI:"
      "\n"
      "There are three towers: A, B, and C.\n"
      "\n"
      "The disks on tower A must be moved to tower C.  Only one\n"
      "disk can be moved at a time, and the order on each tower\n"
      "must be preserved at a time, and the order on each tower\n"
      "or C can be used for intermediate placement of a disk.\n"
      "\n"
      "The problem starts with n disk on Tower A.\n"
      "\n"
      "Input n: ");
   if (scanf("%d", &n) != 1 || n < 1) {
      printf("\nERROR: Positive integer not found - bye!\n\n");
      exit(1);
   }
   printf("\n");
   return n;
}
这里面是不是包括了二叉树的左遍历的知识 
 2006-11-24 10:25
	    2006-11-24 10:25