分别用for循环和递归法求N! ?

[复制链接]
查看11 | 回复3 | 2011-6-3 09:18:47 | 显示全部楼层 |阅读模式
VB代码:------------------------------------------------------------------------for循环_____________________________________________private function jiechengfor(byval n as integer)
dim i as integer,dim jiecheng as long
jiecheng=1
for i =n to 1 step -1
jiecheng=jiecheng*i
next i
...
回复

使用道具 举报

千问 | 2011-6-3 09:18:47 | 显示全部楼层
#include using namespace std;long int non_recursive( int );//非递归实现(用for循环实现)long int recursive( int );//递归实现int main(){int n;long int recursive_r...
回复

使用道具 举报

千问 | 2011-6-3 09:18:47 | 显示全部楼层
int calcNByFor(int n){
int ans=1,i;
for(i=2;i<=n;i++)
ans*=i;
return ans;}int calcNByRec(int n){
if(n<2)
return 1;
else
...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行