天天看點

遞歸實作求n的階乘遞歸實作求n的階乘

遞歸實作求n的階乘

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<time.h>
#include<Windows.h>

/*遞歸和非遞歸分别實作求n的階乘*/
int plusplus(int n)
{
	if (n == 1)
	{
		return 1;
	}
	return n * plusplus(n - 1);
	
}
int main()
{
	int n = 5;
	int ret = plusplus(n);
	printf("%d\n", ret);
	system("pause");
	return 0;
}