递归求阶乘
#include "stdafx.h"
#include<iostream>
using namespace std;
int recursion(const int a);
int _tmain(int argc, _TCHAR* argv[])
{
int num,result;
cout<<"输入要计算阶乘的自然数(0~350):"<<endl;
cin>>num;
if(num<0)
cout<<"警告,请输入正数!"<<endl;
else
result=recursion(num);
cout<<num<<"的阶乘为"<<result<<endl;
return 0;
}
int recursion(const int a)
{
int a_r;
if(a==0)
a_r=1;
else
a_r=a*recursion(a-1);
return a_r;
}